Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 8, 2023
1 parent 687ea81 commit db6ba3d
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 218 deletions.
254 changes: 112 additions & 142 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ enum dir {


func load_slabset():
var CODETIME_START = OS.get_ticks_msec()
var oGame = Nodelist.list["oGame"]

CODETIME_START = OS.get_ticks_msec()

var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT")
var buffer = Filetypes.file_path_to_buffer(filePath)
buffer.seek(2)
var dat_buffer = Filetypes.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
dat_buffer.seek(2)

var totalSlabs = 42 + 16
dat.resize(totalSlabs)
Expand All @@ -43,7 +40,7 @@ func load_slabset():
dat[slabID][variation].resize(9)
if slabID < 42 or variation < 8: # Only fill the data for the first 42 slabs and the first 8 variations of the next 16 slabs
for subtile in 9:
var value = 65536 - buffer.get_u16()
var value = 65536 - dat_buffer.get_u16()
dat[slabID][variation][subtile] = value
else:
for subtile in 9:
Expand All @@ -59,111 +56,8 @@ func load_slabset():

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

func fetch_slab(slabID, variation, subtile):
if dat.size() > slabID:
return dat[slabID][variation][subtile]
else:
return blank_dat_entry[variation][subtile]


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 get_dir_text(variationNumber):
match variationNumber:
00: return 'S'
01: return 'W'
02: return 'N'
03: return 'E'
04: return 'SW'
05: return 'NW'
06: return 'NE'
07: return 'SE'
08: return 'ALL' #SWNE
09: return 'S_LAVA'
10: return 'W_LAVA'
11: return 'N_LAVA'
12: return 'E_LAVA'
13: return 'SW_LAVA'
14: return 'NW_LAVA'
15: return 'NE_LAVA'
16: return 'SE_LAVA'
17: return 'ALL_LAVA' #SWNE_LAVA
18: return 'S_WATER'
19: return 'W_WATER'
20: return 'N_WATER'
21: return 'E_WATER'
22: return 'SW_WATER'
23: return 'NW_WATER'
24: return 'NE_WATER'
25: return 'SE_WATER'
26: return 'ALL_WATER' #SWNE_WATER
27: return 'CENTER'

func load_slabset_things():
CODETIME_START = OS.get_ticks_msec()
var oGame = Nodelist.list["oGame"]
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG")
var buffer = Filetypes.file_path_to_buffer(filePath)
Expand All @@ -172,38 +66,16 @@ func load_slabset_things():
numberOfThings = buffer.get_u16() # It says 359, however there are actually 362 entries in the file.
print('Number of Things: '+str(numberOfThings))

slabtng_index_asset(buffer)
slabtng_object_entry_asset(buffer)

#test_creation_of_object()

func slabtng_index_asset(buffer):
CODETIME_START = OS.get_ticks_msec()

# var textFile = File.new()
# textFile.open("res://slabtng_index_asset.txt", File.WRITE)

buffer.seek(2)
var numberOfSets = 1304
tngIndex.resize(numberOfSets)

for i in tngIndex.size():
var value = buffer.get_u16()
tngIndex[i] = value
#var lineOfText = str(value)
#textFile.store_line(lineOfText)

#textFile.close()
#print('slabtng_index_asset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')

func slabtng_object_entry_asset(buffer):
CODETIME_START = OS.get_ticks_msec()

buffer.seek(2 + (1304*2))

#var textFile = File.new()
#textFile.open("res://slabtng_object_entry_asset.txt", File.WRITE)

tngObject.resize(numberOfThings)
for i in tngObject.size():

Expand Down Expand Up @@ -231,18 +103,116 @@ func slabtng_object_entry_asset(buffer):
tngObject[i][6] = buffer.get_u8() # Thing type
tngObject[i][7] = buffer.get_u8() # Thing subtype
tngObject[i][8] = buffer.get_u8() # Effect range

# textFile.store_line(str(i)+'---------------------')
# for blah in 9:
# textFile.store_line(str(tngObject[i][blah]))

#textFile.close()

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

# tngObject[i][3] = wrapi(file.get_u16(), -511, 65025) / 256.0
# tngObject[i][4] = wrapi(file.get_u16(), -511, 65025) / 256.0
# tngObject[i][5] = wrapi(file.get_u16(), -511, 65025) / 256.0



func fetch_column_index(slabID, variation, subtile):
if dat.size() > slabID:
return dat[slabID][variation][subtile]
else:
return blank_dat_entry[variation][subtile]


#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 get_dir_text(variationNumber):
match variationNumber:
00: return 'S'
01: return 'W'
02: return 'N'
03: return 'E'
04: return 'SW'
05: return 'NW'
06: return 'NE'
07: return 'SE'
08: return 'ALL' #SWNE
09: return 'S_LAVA'
10: return 'W_LAVA'
11: return 'N_LAVA'
12: return 'E_LAVA'
13: return 'SW_LAVA'
14: return 'NW_LAVA'
15: return 'NE_LAVA'
16: return 'SE_LAVA'
17: return 'ALL_LAVA' #SWNE_LAVA
18: return 'S_WATER'
19: return 'W_WATER'
20: return 'N_WATER'
21: return 'E_WATER'
22: return 'SW_WATER'
23: return 'NW_WATER'
24: return 'NE_WATER'
25: return 'SE_WATER'
26: return 'ALL_WATER' #SWNE_WATER
27: return 'CENTER'



#
Expand Down
6 changes: 3 additions & 3 deletions Scenes/PickSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func add_slabs():
match slabID:
Slabs.PORTAL:
for i in 9:
columnArray[i] = Slabset.fetch_slab(slabID, 8, i)
columnArray[i] = Slabset.fetch_column_index(slabID, 8, i)
Slabs.WALL_AUTOMATIC:
for i in 9:
columnArray[i] = Slabset.fetch_slab(Slabs.WALL_WITH_BANNER, slabVariation, i)
columnArray[i] = Slabset.fetch_column_index(Slabs.WALL_WITH_BANNER, slabVariation, i)
_:
if slabID < 1000:
for i in 9:
columnArray[i] = Slabset.fetch_slab(slabID, slabVariation, i)
columnArray[i] = Slabset.fetch_column_index(slabID, slabVariation, i)
else:
# Custom slab
pass
Expand Down
14 changes: 7 additions & 7 deletions Scenes/PlaceThingWithSlab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ onready var oSelector = Nodelist.list["oSelector"]

onready var dir = oSlabPlacement.dir

# The way things placed from slabs.tng works, is that we use the same coordinates (via bitmask and slabVariation) as what's in slabs.dat/clm (level 1000)
# The way things placed from slabs.tng works, is that we use the same coordinates (via bitmask and fullVariationIndex) as what's in slabs.dat/clm (level 1000)
# Except we change the positions based on some placement rules.
# For example the Prison bars need extra rules for detecting nearby walls, but the original slab cubes did not need these rules.
# So objects have their own placement rules, though we use the original bitmask/slabvariation (from oSlabPlacement) as a basis to work from.
# So objects have their own placement rules, though we use the original bitmask/fullVariationIndex (from oSlabPlacement) as a basis to work from.

func place_slab_objects(xSlab, ySlab, slabID, ownership, slabVariation, bitmask, surrID, surrOwner):
func place_slab_objects(xSlab, ySlab, slabID, ownership, fullVariationIndex, bitmask, surrID, surrOwner):
oInstances.delete_attached_objects_on_slab(xSlab, ySlab)

if slabID == Slabs.PRISON:
Expand Down Expand Up @@ -42,9 +42,9 @@ func place_slab_objects(xSlab, ySlab, slabID, ownership, slabVariation, bitmask,
var isMiddle = determine_if_middle(slabID, ownership, bitmask, surrID, surrOwner)
if isMiddle == false:
constructedSlab = oSlabPlacement.slab_all
#print(slabVariation + constructedSlab[0])
#print(fullVariationIndex + constructedSlab[0])
for subtile in 9:
var idx = get_obj_idx(slabVariation + constructedSlab[subtile], subtile)
var idx = get_obj_idx(fullVariationIndex + constructedSlab[subtile], subtile)
if idx != -1:
oInstances.spawn(xSlab, ySlab, slabID, ownership, subtile, Slabset.tngObject[idx])

Expand Down Expand Up @@ -88,8 +88,8 @@ func get_obj_idx(newSlabVar, subtile):

var idx = Slabset.tngIndex[newSlabVar]
if idx >= Slabset.numberOfThings: return -1
# "tngIndex" has one index per slabVariation.
# But there are actually multiple entries inside "tngObject" with the same slabVariation value. Their index is grouped up, that's why I do idx+=1.
# "tngIndex" has one index per fullVariationIndex.
# But there are actually multiple entries inside "tngObject" with the same fullVariationIndex value. Their index is grouped up, that's why I do idx+=1.
while true:
if subtile == Slabset.tngObject[idx][2]:
return idx
Expand Down
Loading

0 comments on commit db6ba3d

Please sign in to comment.