Skip to content

Commit

Permalink
Added Undo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 17, 2024
1 parent 94883c2 commit 1a57d83
Show file tree
Hide file tree
Showing 64 changed files with 1,027 additions and 1,054 deletions.
3 changes: 2 additions & 1 deletion Autoload/Columnset.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends 'res://Class/ClmClass.gd'
onready var oGame = Nodelist.list["oGame"]
onready var oBuffers = Nodelist.list["oBuffers"]

var utilized = []
var orientation = []
Expand Down Expand Up @@ -39,7 +40,7 @@ func load_default_columnset():

func load_default_original_columnset():
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.CLM")
var buffer = Filetypes.file_path_to_buffer(filePath)
var buffer = oBuffers.file_path_to_buffer(filePath)

buffer.seek(0)
var numberOfClmEntries = buffer.get_u16()
Expand Down
2 changes: 1 addition & 1 deletion Autoload/Cube.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func _notification(what: int):
read_cubes_cfg()
# Refresh the display of anything that handles cubes

oOverheadGraphics.update_map_overhead_2d_textures()
oOverheadGraphics.update_full_overhead_map()
oPickSlabWindow.add_slabs()
oColumnEditor._on_ColumnEditor_visibility_changed()
oSlabsetWindow._on_SlabsetWindow_visibility_changed()
Expand Down
5 changes: 3 additions & 2 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node
onready var oGame = Nodelist.list["oGame"]
onready var oMessage = Nodelist.list["oMessage"]
onready var oBuffers = Nodelist.list["oBuffers"]

var tng = []
var dat = []
Expand Down Expand Up @@ -57,8 +58,8 @@ func load_default_slabset():

func load_default_original_slabset():

var dat_buffer = Filetypes.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
var tng_buffer = Filetypes.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG"))
var dat_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
var tng_buffer = oBuffers.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG"))

var object_info = create_object_list(tng_buffer)
if object_info.size() == 0:
Expand Down
49 changes: 49 additions & 0 deletions Class/GridClass.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extends Node
class_name Grid

const U8 = 1
const U16 = 2

var buffer = StreamPeerBuffer.new()
var bytes_per_entry = 1
var width = 0
var height = 0
var buffer_size = 0

func initialize(w, h, fillValue, setPerEntryBytes):
width = w
height = h
bytes_per_entry = setPerEntryBytes
buffer_size = width * height * bytes_per_entry

# Clearing a buffer is troublesome, in order to do so I need to set the buffer to an equal-sized blank PoolByteArray. (this takes 0ms)
var blankByteArray = PoolByteArray([])
blankByteArray.resize(buffer_size)
blankByteArray.fill(fillValue)
buffer.data_array = blankByteArray


func set_cell(x, y, value):
var seek_pos = (y * width + x) * bytes_per_entry
if seek_pos >= 0 and seek_pos < buffer_size:
buffer.seek(seek_pos)
if bytes_per_entry == U8:
buffer.put_u8(value)
elif bytes_per_entry == U16:
buffer.put_u16(value)

func get_cell(x, y):
var seek_pos = (y * width + x) * bytes_per_entry
if seek_pos >= 0 and seek_pos < buffer_size:
buffer.seek(seek_pos)
if bytes_per_entry == U8:
return buffer.get_u8()
elif bytes_per_entry == U16:
return buffer.get_u16()
return -1

func set_cellv(pos, value):
set_cell(pos.x, pos.y, value)

func get_cellv(pos):
return get_cell(pos.x, pos.y)
2 changes: 1 addition & 1 deletion Scenes/3dSelector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extends Spatial
# var clmIndex
# var newSize
# if oGenerateTerrain.GENERATED_TYPE == oGenerateTerrain.GEN_MAP:
# clmIndex = oDataClmPos.get_cell(translation.x,translation.z)
# clmIndex = oDataClmPos.get_cell_clmpos(translation.x,translation.z)
# elif oGenerateTerrain.GENERATED_TYPE == oGenerateTerrain.GEN_CLM:
# clmIndex = oGenerateTerrain.get_clm_index(translation.x,translation.z)
#
Expand Down
2 changes: 1 addition & 1 deletion Scenes/AddCustomSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func copy_values_from_slabset_and_index_them():
func get_column_indexes_on_tile(cursorTile):
for ySubtile in 3:
for xSubtile in 3:
var newIndex = oDataClmPos.get_cell((cursorTile.x*3)+xSubtile, (cursorTile.y*3)+ySubtile)
var newIndex = oDataClmPos.get_cell_clmpos((cursorTile.x*3)+xSubtile, (cursorTile.y*3)+ySubtile)
var i = (ySubtile*3) + xSubtile
customSlabArrayOfSpinbox[i].value = newIndex

Expand Down
2 changes: 1 addition & 1 deletion Scenes/BrushPlacingPreview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func make_brush_shape(constructType):
var endPos = Vector2(oEditingTools.BRUSH_SIZE-1, oEditingTools.BRUSH_SIZE-1)
var brushSize = (beginPos-endPos).abs()
var center = Vector2(brushSize.x*0.5, brushSize.y*0.5)
print("brushSize: " + str(brushSize))

for y in range(beginPos.y, endPos.y+1):
for x in range(beginPos.x, endPos.x+1):
if constructType == oSelection.CONSTRUCT_BRUSH:
Expand Down
104 changes: 59 additions & 45 deletions Autoload/Filetypes.gd → Scenes/Buffers.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
extends Node

onready var oWriteData = Nodelist.list["oWriteData"]
onready var oReadData = Nodelist.list["oReadData"]
onready var oCurrentFormat = Nodelist.list["oCurrentFormat"]

const FILE_TYPES = [
"LOF", # This must be read first so that MAPSIZE can be used in relation to the rest of the files
"CLM",
Expand All @@ -22,9 +26,8 @@ const FILE_TYPES = [
]

func new_blank(EXT):
var oReadData = Nodelist.list["oReadData"]
match EXT:
"LOF" : oReadData.new_keeperfx_lof()
"LOF" : oReadData.new_lof()
"CLM" : oReadData.new_clm()
"DAT" : oReadData.new_dat()
"APT" : oReadData.new_apt()
Expand All @@ -44,17 +47,18 @@ func new_blank(EXT):
"UNE" : oReadData.new_une()

func read(filePath, EXT):

if File.new().file_exists(filePath) == false:
print("File not found : " + filePath)
return
print("Attempting to read : "+filePath)

print("Attempting to read : " + filePath)
var CODETIME_START = OS.get_ticks_msec()

var buffer = file_path_to_buffer(filePath)

var oReadData = Nodelist.list["oReadData"]
read_buffer_for_extension(buffer, EXT)
print('.' + EXT + ' read success in ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')

func read_buffer_for_extension(buffer, EXT):
buffer.seek(0) # Important!
match EXT:
"LOF" : oReadData.read_lof(buffer)
"CLM" : oReadData.read_clm(buffer)
Expand All @@ -74,43 +78,6 @@ func read(filePath, EXT):
"WLB" : oReadData.read_wlb(buffer)
"TXT" : oReadData.read_txt(buffer)
"UNE" : oReadData.read_une(buffer)

print('.'+EXT+' read success in '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')

func write(filePath, EXT):
print("Saving : "+filePath)
var CODETIME_START = OS.get_ticks_msec()

var buffer = StreamPeerBuffer.new()
var oWriteData = Nodelist.list["oWriteData"]
match EXT:
"LOF" : oWriteData.write_keeperfx_lof(buffer)
"CLM" : oWriteData.write_clm(buffer)
"DAT" : oWriteData.write_dat(buffer)
"APT" : oWriteData.write_apt(buffer)
"APTFX" : oWriteData.write_aptfx(buffer)
"TNG" : oWriteData.write_tng(buffer)
"TNGFX" : oWriteData.write_tngfx(buffer)
"INF" : oWriteData.write_inf(buffer)
"SLB" : oWriteData.write_slb(buffer)
"OWN" : oWriteData.write_own(buffer)
"LIF" : oWriteData.write_lif(buffer,filePath)
"LGT" : oWriteData.write_lgt(buffer)
"LGTFX" : oWriteData.write_lgtfx(buffer)
"WIB" : oWriteData.write_wib(buffer)
"SLX" : oWriteData.write_slx(buffer)
"WLB" : oWriteData.write_wlb(buffer)
"TXT" : oWriteData.write_txt(buffer)
"UNE" : oWriteData.write_une(buffer)

var file = File.new()
var err = file.open(filePath,File.WRITE)
if err == OK:
file.store_buffer(buffer.data_array)
print('.'+EXT+' wrote in '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
file.close()

return err

func file_path_to_buffer(filePath):
var buffer = StreamPeerBuffer.new()
Expand All @@ -119,3 +86,50 @@ func file_path_to_buffer(filePath):
buffer.data_array = file.get_buffer(file.get_len())
file.close()
return buffer

func write(filePath, EXT):
print("Saving : " + filePath)
var CODETIME_START = OS.get_ticks_msec()
var buffer = get_buffer_for_extension(EXT, filePath)
var err = write_buffer_to_file(filePath, buffer, EXT, CODETIME_START)
if err == OK:
print('.' + EXT + ' wrote in ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
return err

func write_buffer_to_file(filePath, buffer, EXT, CODETIME_START):
var file = File.new()
var err = file.open(filePath, File.WRITE)
if err == OK:
file.store_buffer(buffer.data_array)
file.close()
return err

func get_buffer_for_extension(EXT, filePath):
match EXT:
"LOF": return oWriteData.write_keeperfx_lof()
"CLM": return oWriteData.write_clm()
"DAT": return oWriteData.write_dat()
"APT": return oWriteData.write_apt()
"APTFX": return oWriteData.write_aptfx()
"TNG": return oWriteData.write_tng()
"TNGFX": return oWriteData.write_tngfx()
"INF": return oWriteData.write_inf()
"SLB": return oWriteData.write_slb()
"OWN": return oWriteData.write_own()
"LIF": return oWriteData.write_lif(filePath)
"LGT": return oWriteData.write_lgt()
"LGTFX": return oWriteData.write_lgtfx()
"WIB": return oWriteData.write_wib()
"SLX": return oWriteData.write_slx()
"WLB": return oWriteData.write_wlb()
"TXT": return oWriteData.write_txt()
"UNE": return oWriteData.write_une()

func should_process_file_type(EXT):
if oCurrentFormat.selected == 0: # Classic format
if ["LOF", "TNGFX", "APTFX", "LGTFX"].has(EXT):
return false
elif oCurrentFormat.selected == 1: # KFX format
if ["LIF", "TNG", "APT", "LGT"].has(EXT):
return false
return true
2 changes: 1 addition & 1 deletion Scenes/CLMGraphics.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends TileMap
# var cubeFace
#
# # clmIndex is a position inside the 2048 column collection
# var clmIndex = oDataClmPos.get_cell(x,y)
# var clmIndex = oDataClmPos.get_cell_clmpos(x,y)
#
# # clmData is the 24 byte array.
# var clmData = oDataClm.data[clmIndex]
Expand Down
1 change: 0 additions & 1 deletion Scenes/Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var middleMousePanning = false
#var mouseIsMoving = false

var mouseInWindow = true
var skip_camera_reset = false

func _ready():
reset_camera(M.xSize, M.ySize)
Expand Down
2 changes: 1 addition & 1 deletion Scenes/ColumnModels.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extends Node
#
# for z in 255:
# for x in 255:
# var idx = oDataClmPos.get_cell(z,x)
# var idx = oDataClmPos.get_cell_clmpos(z,x)
# if oDataClm.solidMask[idx] > 0: # DON'T USE SOLID MASK LIKE THIS!!!!!!!!!!!!!!!!!!!!!!!!
# tempArrays[Mesh.ARRAY_INDEX].append_array(columnMeshArrays[idx][Mesh.ARRAY_INDEX])
# tempArrays[Mesh.ARRAY_VERTEX].append_array(columnMeshArrays[idx][Mesh.ARRAY_VERTEX])
Expand Down
34 changes: 4 additions & 30 deletions Scenes/CurrentMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func _init():
func _on_ButtonNewMap_pressed():
oOpenMap.open_map("") # This means "blank" map


func set_path_and_title(newpath):
if newpath != "":
OS.set_window_title(newpath + ' - Unearth v'+Version.full)
Expand All @@ -49,51 +50,24 @@ func set_path_and_title(newpath):

oGame.reconstruct_command_line() # Always update command line whenever the path changes

var instancesToFree = []
func _process(delta):
# For whatever reason, clearing here instead from an array prevents Godot from crashing
while instancesToFree.empty() == false:
instancesToFree.pop_back().queue_free()

func clear_map():
var allInst = get_tree().get_nodes_in_group("Instance")
for id in allInst:
oInstances.remove_child(id)
id.position = Vector2(-9999999,-9999999)
id.visible = false
for group in id.get_groups():
id.remove_from_group(group)
instancesToFree.append(id)

var CODETIME_START = OS.get_ticks_msec()

set_path_and_title("")
var allInst = get_tree().get_nodes_in_group("Instance")
for id in allInst:
oInstances.kill_instance(id)

# "lif"
oDataMapName.clear()
# "wib"
oDataSlx.clear_img()
# "wib" (Wibble)
oDataWibble.clear()
# "wlb" (Water Lava Block)
oDataLiquid.clear()
# "slb"
oDataSlab.clear()
# "own"
oDataOwnership.clear()
oOverheadOwnership.clear()
# "inf"
oDataLevelStyle.data = 0
# "dat"
oDataClmPos.clear()
# "clm"
oOverheadGraphics.clear_img()
# 3D
oGenerateTerrain.clear()
#"TXT"
oDataScript.data = ""
# "UNE"
oDataFakeSlab.clear()

oScriptHelpers.clear()

Expand Down
2 changes: 1 addition & 1 deletion Scenes/CurrentTextures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func start():
texturesLoadedState = LOADING_SUCCESS

# This is important to do here if updating textures while a map is already open
if oDataSlab.get_cell(0,0) != TileMap.INVALID_CELL:
if oDataSlab.get_cell(0,0) != -1:
set_current_texture_pack()

func scan_dk_data_directory():
Expand Down
8 changes: 4 additions & 4 deletions Scenes/CustomSlabSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func load_file():
}

var retrieve_value
retrieve_value = cfg.get_value(section, "door_thing", null) # Default = null
if retrieve_value != null: slab_dict["door_thing"] = retrieve_value
retrieve_value = cfg.get_value(section, "door_orientation", null)
if retrieve_value != null: slab_dict["door_orientation"] = retrieve_value
retrieve_value = cfg.get_value(section, "door_thing", "NOT_FOUND") # Default = null
if retrieve_value != "NOT_FOUND": slab_dict["door_thing"] = retrieve_value
retrieve_value = cfg.get_value(section, "door_orientation", "NOT_FOUND")
if retrieve_value != "NOT_FOUND": slab_dict["door_orientation"] = retrieve_value

add_custom_slab(slab_dict)

Expand Down
8 changes: 1 addition & 7 deletions Scenes/CustomTooltip.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ func set_floortexture(floorTextureValue):
dataTexture.create_from_image(dataImage, 0)

dataImage.lock()
var valueInput = floorTextureValue
var r = clamp(valueInput, 0, 255)
valueInput -= 255
var g = clamp(valueInput, 0, 255)
valueInput -= 255
var b = clamp(valueInput, 0, 255)
dataImage.set_pixel(0, 0, Color8(r,g,b))
dataImage.set_pixel(0, 0, Color8(floorTextureValue >> 16 & 255, floorTextureValue >> 8 & 255, floorTextureValue & 255))
dataImage.unlock()
dataTexture.set_data(dataImage)

Expand Down
Loading

0 comments on commit 1a57d83

Please sign in to comment.