Skip to content

Commit

Permalink
slabset export
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 13, 2023
1 parent eba799f commit 84bdd07
Show file tree
Hide file tree
Showing 5 changed files with 10,014 additions and 95 deletions.
135 changes: 60 additions & 75 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
extends Node



var tng = []
var numberOfThings = 0

# dat[slabID][variation][subtile]
var dat = []
var blank_dat_entry = []
var CODETIME_START
var default_data = {}

enum obj {
IS_LIGHT, # [0] IsLight [0-1]
Expand Down Expand Up @@ -38,7 +31,7 @@ enum dir {
func load_slabset():
tng = []
dat = []
CODETIME_START = OS.get_ticks_msec()
var CODETIME_START = OS.get_ticks_msec()
var oGame = Nodelist.list["oGame"]
var oMessage = Nodelist.list["oMessage"]

Expand Down Expand Up @@ -75,10 +68,15 @@ func load_slabset():
getObjectIndex += 1

print('Created Slabset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')
store_default_data()

func store_default_data():
default_data["dat"] = dat.duplicate(true)
default_data["tng"] = tng.duplicate(true)

func create_object_list(tng_buffer):
tng_buffer.seek(0)
numberOfThings = tng_buffer.get_u16() # It says 359, however there are actually 362 entries in the file.
var numberOfThings = tng_buffer.get_u16() # It says 359, however there are actually 362 entries in the file.
print('Number of Things: '+str(numberOfThings))

tng_buffer.seek(2 + (1304*2))
Expand Down Expand Up @@ -115,71 +113,58 @@ func fetch_column_index(variation, subtile):
return 0


#func create_cfg_slabset(filePath): #"res://slabset.cfg"
# var oMessage = Nodelist.list["oMessage"]
# var textFile = File.new()
# if textFile.open(filePath, File.WRITE) == OK:
# var slabSection = 0
#
# for slabID in 58:
# #textFile.store_line('[[slab' + str(slabSection) + '.columns]]')
#
# var variationStart = (slabID * 28)
# if slabID >= 42:
# variationStart = (42 * 28) + (8 * (slabID - 42))
#
# var variationCount = 28
# if slabID >= 42:
# variationCount = 8
#
# textFile.store_line('[slab' + str(slabID) + ']')
#
# for variationNumber in variationCount:
# if variationStart + variationNumber < Slabset.dat.size():
# #var beginLine = get_dir_text(variationNumber) + ' = '
# textFile.store_line('[slab' + str(slabSection) + '.' + get_dir_text(variationNumber) + ']')
# textFile.store_line('columns = ' + String(Slabset.dat[variationStart + variationNumber])) #.replace(',','').replace('[','').replace(']','')
#
# #var objectNumber = 0
# var hasObjects = false
# for i in tngObject.size():
# if tngObject[i][1] == variationStart + variationNumber: #VariationIndex
# textFile.store_line("\r")
# hasObjects = true
# textFile.store_line('[[slab' + str(slabSection) + '.' + get_dir_text(variationNumber) + '_objects' + ']]')
# for z in 9:
# var val = tngObject[i][z]
# var beginLine = ''
# match z:
# 0: beginLine = 'IsLight'
# 1: beginLine = 'VariationIndex'
# 2: beginLine = 'Subtile'
# 3: beginLine = 'RelativeX'
# 4: beginLine = 'RelativeY'
# 5: beginLine = 'RelativeZ'
# 6: beginLine = 'ThingType'
# 7: beginLine = 'Subtype'
# 8: beginLine = 'EffectRange'
# if z == 1: continue # skip "VariationIndex"
#
# beginLine += ' = '
#
# textFile.store_line(beginLine + String(val))
# #objectNumber += 1
#
# if hasObjects == false:
# textFile.store_line('objects = []')
#
# textFile.store_line("\r")
#
# textFile.store_line("\r")
#
# slabSection += 1
#
# textFile.close()
# oMessage.quick("aaaaa Saved: " + filePath)
# else:
# oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")
func create_cfg_slabset(filePath): #"res://slabset.cfg"
var CODETIME_START = OS.get_ticks_msec()
var oMessage = Nodelist.list["oMessage"]
var textFile = File.new()
if textFile.open(filePath, File.WRITE) != OK:
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")
return

for variation in dat.size():
var slabID = int(variation / 28)
var variationNumber = variation % 28
var dirText = get_dir_text(variationNumber)

if variationNumber == 0:
textFile.store_line("[slab" + str(slabID) + "]")
textFile.store_line("[slab" + str(slabID) + "." + dirText + "]")
textFile.store_line("columns = " + str(dat[variation]))

for object in tng[variation]:
textFile.store_line("\r")
textFile.store_line("[[slab" + str(slabID) + "." + dirText + "_objects" + "]]")
for z in 9:
var val = object[z]
var beginLine = get_property_name(z) # Implement this method based on your match statement.
if beginLine:
beginLine += " = "
if z == obj.THING_TYPE: # Use string as value instead of an integer
if object[obj.IS_LIGHT] == 1:
val = '"Unused"' # Lights don't use ThingType field
else:
val = '"'+Things.data_structure_name.get(val, "?")+'"'
textFile.store_line(beginLine + str(val))
if tng[variation].size() == 0:
textFile.store_line("objects = []")
textFile.store_line("\r")

textFile.close()
oMessage.quick("Saved: " + filePath)

print('Exported in: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')

func get_property_name(i):
match i:
obj.IS_LIGHT: return 'IsLight'
obj.SUBTILE: return 'Subtile'
obj.RELATIVE_X: return 'RelativeX'
obj.RELATIVE_Y: return 'RelativeY'
obj.RELATIVE_Z: return 'RelativeZ'
obj.THING_TYPE: return 'ThingType'
obj.THING_SUBTYPE: return 'Subtype'
obj.EFFECT_RANGE: return 'EffectRange'
_: return ''

func get_dir_text(variationNumber):
match variationNumber:
Expand Down
45 changes: 27 additions & 18 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,39 @@ const LIGHT_LIMIT = -1
enum TYPE {
NONE = 0
OBJECT = 1
#TCls_Shot = 2
#TCls_EffectElem = 3
#TCls_DeadCreature = 4
SHOT = 2
EFFECTELEM = 3
DEADCREATURE = 4
CREATURE = 5
#TCls_Effect = 6
EFFECT = 6
EFFECTGEN = 7
TRAP = 8
DOOR = 9
#TCls_Unkn10 = 10
#TCls_Unkn11 = 11
#TCls_AmbientSnd = 12
#TCls_CaveIn = 13
UNKN10 = 10
UNKN11 = 11
AMBIENTSND = 12
CAVEIN = 13
EXTRA = 696969
}

var data_structure_name = {
TYPE.NONE: "Empty",
TYPE.OBJECT: "Object",
TYPE.SHOT: "Shot",
TYPE.EFFECTELEM: "EffectElem",
TYPE.DEADCREATURE: "DeadCreature",
TYPE.CREATURE: "Creature",
TYPE.EFFECT: "Effect",
TYPE.EFFECTGEN: "EffectGen",
TYPE.TRAP: "Trap",
TYPE.DOOR: "Door",
TYPE.UNKN10: "Unkn10",
TYPE.UNKN11: "Unkn11",
TYPE.AMBIENTSND: "AmbientSnd",
TYPE.CAVEIN: "CaveIn",
TYPE.EXTRA: "Extra"
}

enum {
NAME = 0
KEEPERFX_NAME = 1
Expand Down Expand Up @@ -86,16 +105,6 @@ func data_structure(thingType):
print("This should never happen.")
return {}

func data_structure_name(thingType):
match thingType:
Things.TYPE.OBJECT: return "Object"
Things.TYPE.CREATURE: return "Creature"
Things.TYPE.EFFECTGEN: return "Effectgen"
Things.TYPE.TRAP: return "Trap"
Things.TYPE.DOOR: return "Door"
Things.TYPE.EXTRA: return "Extra"
return "Name not found"

var DATA_EXTRA = {
0 : [null, null, null, null, null, null],
1 : ["Action Point", null, null, preload("res://Art/ActionPoint.png"), null, TAB_ACTION],
Expand Down
2 changes: 1 addition & 1 deletion Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func _on_ObjDeleteButton_pressed():
oMessage.quick("Deleted object")

func _on_ObjThingTypeSpinBox_value_changed(value:int):
oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name(value)
oObjThingTypeSpinBox.hint_tooltip = Things.data_structure_name.get(value, "?")
#yield(get_tree(),'idle_frame')
update_obj_name()
update_object_property(Slabset.obj.THING_TYPE, value)
Expand Down
8 changes: 7 additions & 1 deletion Scenes/VoxelViewer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ environment = SubResource( 19 )
[sub_resource type="SpatialMaterial" id=21]
flags_transparent = true
vertex_color_use_as_albedo = true
albedo_color = Color( 0.752941, 0.752941, 1, 0.188235 )
albedo_color = Color( 1, 1, 1, 0.188235 )

[node name="VoxelObjectView" type="ViewportContainer" groups=["VoxelViewer"]]
margin_right = 1236.0
Expand All @@ -25,6 +25,12 @@ size_flags_vertical = 3
stretch = true
script = ExtResource( 4 )

[node name="ColorRectBack" type="ColorRect" parent="."]
show_behind_parent = true
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.152941, 0.145098, 0.172549, 1 )

[node name="VoxelViewport" type="Viewport" parent="."]
size = Vector2( 1236, 620 )
own_world = true
Expand Down
Loading

0 comments on commit 84bdd07

Please sign in to comment.