Skip to content

Commit

Permalink
Stability improvements, Clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
SkogrKrellr committed Jan 9, 2022
1 parent 02e7249 commit 8bbde7b
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 166 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ Some examples of terrain generation: *(Skies are edited after the fact)*

You will need to have Python3 ( v3.9 or above) installed, and Talespire installed on your machine.

1. Clone the repo to your local
1. Clone the repo to your local machine
2. Locate `index.json` file in Talespire installation folder.
Most likely it is in: `..\Steam\steamapps\common\TaleSpire\Taleweaver\d71427a1-5535-4fa7-82d7-4ca1e75edbfd`
Place the *index.json* in the `etc` folder of the cloned repository
3. Run the setup script with the command:

```bash
# All commands are run from TaleSpire_Generator directory
# This will install required packages
pip install -r requirements.txt
# This will create and populate the database
Expand Down
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = database
assets = Assets

[visualizer]
cmap = gist_earth
cmap = binary

[generator]
default_x = 10
Expand Down
1 change: 1 addition & 0 deletions etc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.json goes in this folder here!
45 changes: 3 additions & 42 deletions generator/generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import math
import numpy
from generator.modifications import *
from objects.tile import Tile
from objects.assetManager import AssetManager
from objects.customAsset import CustomAsset
Expand Down Expand Up @@ -51,7 +52,6 @@ def __init__(self):
"""
Constructor for Generator class.
"""

self.setXYZ(DEFAULT_X, DEFAULT_Y, DEFAULT_Z)
self.setSeed(DEFAULTSEED)
self.setOctaves(1, 0.5, 0.25, 0.125)
Expand Down Expand Up @@ -273,45 +273,6 @@ def adaptiveThickness(self, x, y, z):
1
))

# Elevation Modifiers
def multiplyByValue(self, value=None):
"""
Function to multiply elevation by a value.
If no value is provided, it will be multiplied by Z height
Parameters:
value (float): value for elevation multiplication
"""

if value is None:
value = self.z
self.elevation *= value

def createTerrases(self, steps):
"""
Function to devide terrain into step ammount of terrases
Parameters:
steps (int): number of terrasses to be generated
"""

self.elevation = numpy.floor(self.elevation*steps)/steps

def redistribute(self, value=None):
"""
Function to remap values by replacing each elevation value
by an exponated version of it.
If no value is provided, exponent value will be used.
Parameters:
value (float): exponent
"""

if value is None:
value = self.exponent
self.elevation **= value

# Generation
def generate(
self,
Expand Down Expand Up @@ -344,8 +305,8 @@ def generate(
self.y*sizes[1],
terrainAssets
)
self.redistribute()
self.multiplyByValue()
redistribute(self.elevation, self.exponent)
multiplyByValue(self.elevation, self.z)
self.setTileSize(self.terrainAssets[0].mExtent.x*2.0)

self.generatePlaceObjects(
Expand Down
123 changes: 123 additions & 0 deletions generator/modifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import numpy


def multiplyByValue(noiseMap, value):
"""
Function to multiply noisemap by a value.
Parameters:
noieMap (array): noisemap to be changed
value (float): value for multiplication
Returns:
array: modified noiseMap
"""

noiseMap *= value
return noiseMap


def createTerrases(noiseMap, steps):
"""
Function to create terrasses.
Parameters:
noieMap (array): noisemap to be changed
steps (int): amount of terrase levels
Returns:
array: modified noiseMap
"""

noiseMap = numpy.floor(noiseMap*steps)/steps
return noiseMap


def redistribute(noiseMap, exponent):
"""
Function to redestribute values with exponent.
Parameters:
noieMap (array): noisemap to be changed
exponent (float): exponent to be applied
Returns:
array: modified noiseMap
"""

noiseMap **= exponent
return noiseMap


def ridgeNoise(noiseMap):
"""
Function to change the distribution of values.
The new distribution follows the formula:
y = 2 * (0.5 - abs(0.5 - x))
y - new value
x - old value
Parameters:
noieMap (array): noisemap to be changed
Returns:
array: modified noiseMap
"""

noiseMap = 2 * (0.5 - abs(0.5 - noiseMap))
return noiseMap


def raiseFloor(noiseMap, level):
"""
Function to set a floor level
Parameters:
noieMap (array): noisemap to be changed
level (float): floor level (0.0 - 1.0)
Returns:
array: modified noiseMap
"""
for y, x in numpy.ndindex(noiseMap.shape):
noiseMap[y, x] = max(noiseMap[y][x], level)
return noiseMap


def lowerCeiling(noiseMap, level):
"""
Function to set a ceiling level
Parameters:
noieMap (array): noisemap to be changed
level (float): floor level (0.0 - 1.0)
Returns:
array: modified noiseMap
"""

for y, x in numpy.ndindex(noiseMap.shape):
noiseMap[y, x] = min(noiseMap[y][x], level)
return noiseMap


def normalize(noiseMap):
"""
Function to set a set scale noiseMap, so that its lowest
value would be 0.0 and the highest value 1.0
Parameters:
noieMap (array): noisemap to be changed
Returns:
array: modified noiseMap
"""

min = numpy.amin(noiseMap)
max = numpy.amax(noiseMap)

noiseMap -= min
noiseMap /= (max-min)
return noiseMap
53 changes: 14 additions & 39 deletions generator/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy
from opensimplex import OpenSimplex
from config.config import config as Config
from generator.modifications import *
from visualizer.visualizer import Visualizer


Expand Down Expand Up @@ -87,32 +88,10 @@ def getNoiseXYValue(self, x, y, scaleX, scaleY):
value = self.noiseXY(x/scaleX, y/scaleY)
return (1 + value) * 0.5

def getRidgeNoiseXY(self, x, y, scaleX, scaleY):
"""
Function to change the distribution of values.
The new distribution follows the formula:
y = 2 * abs(0.5 - x)
y - new value
x - old value
Parameters:
x (int): X coordinate for noise
y (int): Y coordinate for noise
scaleX (float): Scaling factor for X
scaleY (float): Scaling factor for Y
Returns:
float: value at that scaled coordinate from 0.0 to 1.0
"""

noiseValue = self.getNoiseXYValue(x, y, scaleX, scaleY)
return 2 * (0.5 - abs(0.5 - noiseValue))

def generateSimpleNoiseArray(
self,
xSize, ySize,
xSize,
ySize,
scaleX,
scaleY=None,
offset={"x": 0, "y": 0},
Expand Down Expand Up @@ -140,25 +119,21 @@ def generateSimpleNoiseArray(
currentPass = numpy.zeros((xSize, ySize))
for x in range(0, xSize):
for y in range(0, ySize):
if useRidgeNoise:
currentPass[x][y] = self.getRidgeNoiseXY(
x + offset["x"],
y + offset["y"],
scaleX,
scaleY
)
else:
currentPass[x][y] = self.getNoiseXYValue(
x + offset["x"],
y + offset["y"],
scaleX,
scaleY
)
currentPass[x][y] = self.getNoiseXYValue(
x + offset["x"],
y + offset["y"],
scaleX,
scaleY
)

if useRidgeNoise:
currentPass = ridgeNoise(currentPass)
return currentPass

def generateComplexNoiseArray(
self,
xSize, ySize,
xSize,
ySize,
maxSize,
combinedPasses=True,
octaves=None,
Expand Down
18 changes: 9 additions & 9 deletions objects/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from objects.quad import Quad
from config.config import config as Config

TABLE_NAME = DATABASE_NAME = Config.get('tableName', 'assets')
TABLE_NAME = Config.get('tableName', 'assets')


class Asset:
Expand Down Expand Up @@ -153,11 +153,11 @@ def SqlCreateTable() -> str:
Name tinytext NOT NULL,
AssetName tinytext NOT NULL,
String text NULL,
{Quad.SqlCreateTable("Position")},
{Quad.SqlCreateTable("Rotation")},
{Quad.SqlCreateTable("Scale")},
{Quad.SqlCreateTable("mCenter")},
{Quad.SqlCreateTable("mExtent")}
{Quad.SqlCreateFields("Position")},
{Quad.SqlCreateFields("Rotation")},
{Quad.SqlCreateFields("Scale")},
{Quad.SqlCreateFields("mCenter")},
{Quad.SqlCreateFields("mExtent")}
);""".replace(" ", "").strip()

return output
Expand All @@ -170,7 +170,7 @@ def SqlDropTable():
str: An SQL expression for creating table for assets.
"""

return f""" DROP TABLE IF EXISTS {TABLE_NAME}; """
return f"""DROP TABLE IF EXISTS {TABLE_NAME};"""

def SqlGetAsset(uuid):
"""
Expand All @@ -183,7 +183,7 @@ def SqlGetAsset(uuid):
str: An SQL expression for get asset from specific table.
"""

return f""" SELECT * FROM {TABLE_NAME} WHERE UUID = '{uuid}'; """
return f"""SELECT * FROM {TABLE_NAME} WHERE UUID = '{uuid}';"""

def SqlDeleteAsset(uuid):
"""
Expand All @@ -196,4 +196,4 @@ def SqlDeleteAsset(uuid):
str: An SQL expression for remove asset from specific table.
"""

return f""" DELETE FROM {TABLE_NAME} WHERE UUID = '{uuid}'; """
return f"""DELETE FROM {TABLE_NAME} WHERE UUID = '{uuid}';"""
6 changes: 4 additions & 2 deletions objects/customAsset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def __init__(
"""

Asset.__init__(self, object)
self.determineSize()

def determineSize(self):
if(
self.mCenter == Quad(0, 0, 0, 0) or
self.mExtent == Quad(0, 0, 0, 0)
):
decoded = ConversionManager.decode(self.string)
dictionary = decoded['asset_data']
dictionary = self.getDecoded()
offset = {}
extentsMax = {
"x": 0,
Expand Down
2 changes: 1 addition & 1 deletion objects/quad.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def SqlFieldNames(prefix=""):

return f"{prefix}_x, {prefix}_y, {prefix}_z, {prefix}_w"

def SqlCreateTable(prefix=""):
def SqlCreateFields(prefix=""):
"""
Function to create table columns for Quad with a specific prefix.
Expand Down
Loading

0 comments on commit 8bbde7b

Please sign in to comment.