Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 27, 2022
1 parent 349140b commit 4f001b3
Show file tree
Hide file tree
Showing 24 changed files with 294 additions and 133 deletions.
7 changes: 7 additions & 0 deletions AutoLoad/Cube.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
extends Node

var data = []

#func _ready():
# var cubesCfgFilePath = oGame.get_precise_filepath(oGame.DK_FXDATA_DIRECTORY, "CUBES.CFG")
# data.append(0)


enum {
RED = 0
BLUE = 1
Expand Down
7 changes: 6 additions & 1 deletion AutoLoad/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ var listOfSettings = [
"frail_impenetrable",
"wallauto_art",
"wallauto_damaged",
"recently_opened"
"recently_opened",
"placing_tutorial",
# These four are read inside Viewport script
# "editor_window_position",
# "editor_window_size",
Expand Down Expand Up @@ -334,6 +335,10 @@ func game_setting(doWhat,string,value):
var oMenu = $'../Main/Ui/UiSystem/Menu'
if doWhat == SET: oMenu.initialize_recently_opened(value)
if doWhat == GET: return oMenu.recentlyOpened
"placing_tutorial":
var oPlacingTipsButton = $"../Main/Ui/UiTools/PropertiesWindow/VBoxContainer/PropertiesTabs/PlacingSettings/PlacingTipsButton"
if doWhat == SET: oPlacingTipsButton.visible = value
if doWhat == GET: return oPlacingTipsButton.visible

func delete_settings():
var dir = Directory.new()
Expand Down
2 changes: 2 additions & 0 deletions Scenes/CurrentMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ onready var oDataScript = Nodelist.list["oDataScript"]
onready var oScriptHelpers = Nodelist.list["oScriptHelpers"]
onready var oDataCustomSlab = Nodelist.list["oDataCustomSlab"]
onready var oSlabPlacement = Nodelist.list["oSlabPlacement"]
onready var oMenu = Nodelist.list["oMenu"]


var path = ""
Expand All @@ -40,6 +41,7 @@ func set_path_and_title(newpath):

if newpath != "":
OS.set_window_title(newpath + ' - Unearth v'+Constants.VERSION)
oMenu.add_recent(newpath) # Add saved maps to the recent menu
else:
OS.set_window_title('Unearth v'+Constants.VERSION)
path = newpath
Expand Down
2 changes: 1 addition & 1 deletion Scenes/DkClm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func clm_load_slabset():
clear_all_column_data() # Important, for reloading/refreshing slabs.clm


var filePath = oDkDat.dk_data_get_filepath("SLABS.CLM")
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.CLM")
var buffer = Filetypes.file_path_to_buffer(filePath)

buffer.seek(0)
Expand Down
16 changes: 1 addition & 15 deletions Scenes/DkDat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var dat = [] # 1304 sets of 9 column indexes
func dat_load_slabset():
var CODETIME_START = OS.get_ticks_msec()

var filePath = dk_data_get_filepath("SLABS.DAT")
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT")
var buffer = Filetypes.file_path_to_buffer(filePath)
buffer.seek(2)
var numberOfSets = 1304
Expand All @@ -19,17 +19,3 @@ func dat_load_slabset():
dat[i][subtile] = value

print('Created DAT asset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')



func dk_data_get_filepath(lookForFileName):
var dir = Directory.new()
if dir.open(oGame.DK_DATA_DIRECTORY) == OK:
dir.list_dir_begin(true, false)
var fileName = dir.get_next()
while fileName != "":
if dir.current_is_dir() == false:
if fileName.to_upper() == lookForFileName.to_upper(): # Get file regardless of case (case insensitive)
return oGame.DK_DATA_DIRECTORY.plus_file(fileName)
fileName = dir.get_next()
return ""
1 change: 1 addition & 0 deletions Scenes/Editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ onready var oEditingMode = Nodelist.list["oEditingMode"]
onready var oEditableBordersCheckbox = Nodelist.list["oEditableBordersCheckbox"]
onready var oMenu = Nodelist.list["oMenu"]
onready var oConfirmSaveBeforeQuit = Nodelist.list["oConfirmSaveBeforeQuit"]
onready var oReadCubes = Nodelist.list["oReadCubes"]

enum {
VIEW_2D = 0
Expand Down
21 changes: 17 additions & 4 deletions Scenes/GamePaths.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var EXECUTABLE_PATH = ""
var SAVE_AS_DIRECTORY = ""
var GAME_DIRECTORY = ""
var DK_DATA_DIRECTORY = ""
var DK_FXDATA_DIRECTORY = ""

#var nosound = true
#var cheats = true
Expand All @@ -38,9 +39,10 @@ func set_paths(path):
EXECUTABLE_PATH = path
GAME_DIRECTORY = path.get_base_dir()

for i in get_subdirs(GAME_DIRECTORY):
if i.to_upper() == "DATA":
DK_DATA_DIRECTORY = GAME_DIRECTORY.plus_file(i)
for i in get_main_subdirectories(GAME_DIRECTORY): # Directories only
match i.to_upper():
"DATA": DK_DATA_DIRECTORY = GAME_DIRECTORY.plus_file(i)
"FXDATA": DK_FXDATA_DIRECTORY = GAME_DIRECTORY.plus_file(i)

func _on_CmdLineDkCommands_text_changed(new_text):
Settings.set_setting("dk_commands", new_text)
Expand Down Expand Up @@ -117,7 +119,7 @@ func menu_play_clicked():
oSaveMap.save_map(oCurrentMap.path)
launch_game()

func get_subdirs(path):
func get_main_subdirectories(path):
var array = []
var dir = Directory.new()
if dir.open(path) == OK:
Expand Down Expand Up @@ -151,6 +153,17 @@ func test_write_permissions():
oMessage.big("Error", "There are no write permissions for your Dungeon Keeper directory. Maybe try moving your Dungeon Keeper folder elsewhere, then choose the executable again.")
return err

func get_precise_filepath(lookInDirectory, lookForFileName):
var dir = Directory.new()
if dir.open(lookInDirectory) == OK:
dir.list_dir_begin(true, false)
var fileName = dir.get_next()
while fileName != "":
if dir.current_is_dir() == false:
if fileName.to_upper() == lookForFileName.to_upper(): # Get file regardless of case (case insensitive)
return lookInDirectory.plus_file(fileName)
fileName = dir.get_next()
return ""


#func load_command_line_from_settings(COMMAND_LINE):
Expand Down
106 changes: 72 additions & 34 deletions Scenes/GenerateBorderWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,66 @@ onready var oNoiseLacunarity = Nodelist.list["oNoiseLacunarity"]
onready var oOverheadGraphics = Nodelist.list["oOverheadGraphics"]
onready var oDataClm = Nodelist.list["oDataClm"]
onready var oQuickNoisePreview = Nodelist.list["oQuickNoisePreview"]
onready var oNoiseUpdateTimer = Nodelist.list["oNoiseUpdateTimer"]
onready var oNewMapBorderOptions = Nodelist.list["oNewMapBorderOptions"]

var noise = OpenSimplexNoise.new()
var imageData = Image.new()
var textureData = ImageTexture.new()

func _process(delta):
if visible == false: return

noise.octaves = oNoiseOctaves.value
noise.period = oNoisePeriod.value
noise.persistence = oNoisePersistence.value
noise.lacunarity = oNoiseLacunarity.value

oQuickNoisePreview.texture.noise = noise
const earthColour = Color8(255,255,255,255)#Color8(36,24,0,255)
const impenetrableColour = Color8(0,0,0,255)

func _on_NoiseButtonApply_pressed():
var TOTALCODETIME_START = OS.get_ticks_msec()

# If a map is open, then clear it (remove objects and ownership and such)
if oCurrentMap.path != "":
oCurrentMap._on_ButtonNewMap_pressed()
func _ready():
imageData.create(85, 85, false, Image.FORMAT_RGB8)
textureData.create_from_image(imageData, 0)
oQuickNoisePreview.texture = textureData

func _on_NewMapWindow_visibility_changed():
if visible == true:
randomize()
noise.seed = randi()
update_border_image_with_noise()

func _on_ButtonNewMapOK_pressed():
oCurrentMap._on_ButtonNewMap_pressed()

# If field is black (no map has been opened), then we need something to start with
if oDataClm.cubes.empty() == true:
oCurrentMap._on_ButtonNewMap_pressed()
if oNewMapBorderOptions.visible == true:
update_border_image_with_noise()
overwrite_map_with_border_values()

# Make fully rock and clear previous
visible = false # Close New Map window after pressing OK button

func overwrite_map_with_border_values():
imageData.lock()
for x in range(1, 84):
for y in range(1, 84):
oDataSlab.set_cell(x,y, Slabs.ROCK)

match imageData.get_pixel(x,y):
impenetrableColour: oDataSlab.set_cell(x, y, Slabs.ROCK)
earthColour: oDataSlab.set_cell(x, y, Slabs.EARTH)
imageData.unlock()
oSlabPlacement.generate_slabs_based_on_id(Vector2(0,0), Vector2(84,84), false)

func _on_NoisePersistence_sliderChanged():
# Constantly reset the timer to max time while dragging the slider
# When timer ends, update the visual
oNoiseUpdateTimer.start(0.01)
func _on_NoisePeriod_sliderChanged():
oNoiseUpdateTimer.start(0.01)
func _on_NoiseLacunarity_sliderChanged():
oNoiseUpdateTimer.start(0.01)
func _on_NoiseOctaves_sliderChanged():
oNoiseUpdateTimer.start(0.01)

func _on_NoiseUpdateTimer_timeout():
update_border_image_with_noise()

func update_border_image_with_noise():
var NOISECODETIME = OS.get_ticks_msec()

randomize()
noise.seed = randi()
noise.octaves = oNoiseOctaves.value
noise.period = oNoisePeriod.value
noise.persistence = oNoisePersistence.value
noise.lacunarity = oNoiseLacunarity.value

var fullMapSize = 84.0 #84.0
var halfMapSize = fullMapSize * 0.5
Expand All @@ -59,28 +86,39 @@ func _on_NoiseButtonApply_pressed():

var coordsToCheck = [Vector2(42,42)]


imageData.fill(impenetrableColour)
imageData.lock()
while coordsToCheck.size() > 0:
var coord = coordsToCheck.pop_back()
if floodFillTileMap.get_cellv(coord) == 1:
floodFillTileMap.set_cellv(coord, 0)

oDataSlab.set_cellv(coord, Slabs.EARTH)
imageData.set_pixelv(coord, earthColour)

coordsToCheck.append(coord + Vector2(0,1))
coordsToCheck.append(coord + Vector2(0,-1))
coordsToCheck.append(coord + Vector2(1,0))
coordsToCheck.append(coord + Vector2(-1,0))
imageData.unlock()
textureData.set_data(imageData)

print('Noise time: ' + str(OS.get_ticks_msec() - NOISECODETIME) + 'ms')

oSlabPlacement.generate_slabs_based_on_id(Vector2(0,0), Vector2(84,84), false)
print('Codetime: ' + str(OS.get_ticks_msec() - TOTALCODETIME_START) + 'ms')
print('Border image time: ' + str(OS.get_ticks_msec() - NOISECODETIME) + 'ms')

func update_border_image_with_blank():
imageData.fill(earthColour)
imageData.lock()
for x in 85:
for y in 85:
if x == 0 or x == 84 or y == 0 or y == 84:
imageData.set_pixel(x,y, impenetrableColour)
imageData.unlock()
textureData.set_data(imageData)

func _on_ButtonBlankMap_pressed():
oCurrentMap._on_ButtonNewMap_pressed()

func _on_CheckBoxNewMapBorder_pressed():
oNewMapBorderOptions.visible = true
update_border_image_with_noise()

func _on_NewMapCloseButton_pressed():
visible = false
func _on_CheckBoxNewMapBlank_pressed():
oNewMapBorderOptions.visible = false
update_border_image_with_blank()
Loading

0 comments on commit 4f001b3

Please sign in to comment.