Skip to content

Commit

Permalink
cfg refactor wip 4
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 11, 2024
1 parent 07ae46f commit eb52484
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
12 changes: 9 additions & 3 deletions Autoload/Things.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ enum TYPE {
}

func fetch_name(thing_type, sub_type):
if NAME_MAPPINGS.has(thing_type):
var dictionary_of_names = NAME_MAPPINGS[thing_type]
return dictionary_of_names.get(sub_type, "Unknown " + data_structure_name[thing_type] + " " + str(sub_type))
var dictionary_of_names = NAME_MAPPINGS.get(thing_type)
if dictionary_of_names:
var data_structure = data_structure(thing_type)
var sub_type_data = data_structure.get(sub_type)
if sub_type_data:
var nameId = sub_type_data[NAME_ID]
return dictionary_of_names.get(nameId, nameId.capitalize())
else:
return "Unknown " + data_structure_name[thing_type] + " Subtype: " + str(sub_type)
else:
return "Unknown Thingtype " + str(thing_type) + ", Subtype: " + str(sub_type)

Expand Down
3 changes: 2 additions & 1 deletion Scenes/DisplayOverlapping.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ func update_overlap_tree():
for i in oSelection.cursorOnInstancesArray:
if is_instance_valid(i) and i.is_queued_for_deletion() == false:
var item = oTreeOfOverlaps.create_item(treeRoot)
item.set_text(0, oThingDetails.retrieve_thing_name(i.thingType, i.subtype))
item.set_text(0, Things.fetch_name(i.thingType, i.subtype))
rect_size.y += 29


var highlightItem = oTreeOfOverlaps.get_item_at_position(Vector2(10,10))
if is_instance_valid(highlightItem) and highlightItem.is_queued_for_deletion() == false:
Expand Down
8 changes: 5 additions & 3 deletions Scenes/PickThingWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func initialize_thing_grid_items():
print('Initialized Things window: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')


func add_to_category(tabNode, thingsData, type, subtype):
func add_to_category(tabNode, thingsData, thingtype, subtype):
var gridcontainer = get_grid_container_node(tabNode)

var id = scnGridItem.instance()
id.img_margin = 3
id.connect('mouse_entered',oThingDetails,"_on_thing_portrait_mouse_entered",[id])
id.connect('gui_input',self,"_on_thing_portrait_gui_input",[id])
id.set_meta("thingSubtype", subtype)
id.set_meta("thingType", type)
id.set_meta("thingType", thingtype)

# Appearance prioritization: Portrait > Texture > ThingDarkened.png
var portraitTex = thingsData[subtype][Things.PORTRAIT]
Expand All @@ -122,7 +122,9 @@ func add_to_category(tabNode, thingsData, type, subtype):
else:
id.img_normal = preload('res://Art/ThingDarkened.png')

var setText = thingsData[subtype][Things.NAME]


var setText = Things.fetch_name(thingtype, subtype)

add_item_to_grid(gridcontainer, id, setText)

Expand Down
2 changes: 1 addition & 1 deletion Scenes/PlacingSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func update_placing_tab():
match i:
FIELDS.ID:
description = "ID"
value = oThingDetails.retrieve_thing_name(thingType, subtype)
value = Things.fetch_name(thingType, subtype)
FIELDS.TYPE:
description = "Type"
value = oThingDetails.retrieve_subtype_value(thingType, subtype)
Expand Down
11 changes: 2 additions & 9 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,9 @@ func update_obj_name():
if oObjIsLightCheckBox.pressed == true:
oObjNameLabel.text = "Light"
else:
var dataStruct = Things.data_structure(int(oObjThingTypeSpinBox.value))
var thingType = int(oObjThingTypeSpinBox.value)
var subtype = int(oObjSubtypeSpinBox.value)
if dataStruct.has(subtype):
var newName = dataStruct[subtype][Things.NAME]
if newName is String:
oObjNameLabel.text = newName
else:
oObjNameLabel.text = "Name not found"
else:
oObjNameLabel.text = "Name not found"
oObjNameLabel.text = Things.fetch_name(thingType, subtype)

func _on_ObjAddButton_pressed():
var variation = get_current_variation()
Expand Down
53 changes: 15 additions & 38 deletions Scenes/ThingDetails.gd
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func thing_details(id):
match i:
0:
description = "ID"
value = retrieve_thing_name(id.thingType, id.subtype)
value = Things.fetch_name(id.thingType, id.subtype)
1:
description = "Type"
value = retrieve_subtype_value(id.thingType, id.subtype)
Expand Down Expand Up @@ -194,42 +194,6 @@ func _on_SelectionStatusButton_mouse_entered():
func _on_SelectionStatusButton_mouse_exited():
oSelectionStatusButton.text = "Selected"

func retrieve_thing_name(t_type, s_type): # called by ThingInstance too
match t_type:
Things.TYPE.OBJECT:
if Things.DATA_OBJECT.has(s_type):
return Things.DATA_OBJECT[s_type][Things.NAME]
Things.TYPE.CREATURE:
if Things.DATA_CREATURE.has(s_type):
return Things.DATA_CREATURE[s_type][Things.NAME]
Things.TYPE.EFFECTGEN:
if Things.DATA_EFFECTGEN.has(s_type):
return Things.DATA_EFFECTGEN[s_type][Things.NAME]
Things.TYPE.TRAP:
if Things.DATA_TRAP.has(s_type):
return Things.DATA_TRAP[s_type][Things.NAME]
Things.TYPE.DOOR:
if Things.DATA_DOOR.has(s_type):
return Things.DATA_DOOR[s_type][Things.NAME]
Things.TYPE.EXTRA:
if Things.DATA_EXTRA.has(s_type):
return Things.DATA_EXTRA[s_type][Things.NAME]
return "Unknown"

func retrieve_subtype_value(t_type, s_type):
match t_type:
Things.TYPE.NONE: return "None" + " : " + str(s_type)
Things.TYPE.OBJECT: return "Object" + " : " + str(s_type)
Things.TYPE.CREATURE: return "Creature" + " : " + str(s_type)
Things.TYPE.EFFECTGEN: return "EffectGen" + " : " + str(s_type)
Things.TYPE.TRAP: return "Trap" + " : " + str(s_type)
Things.TYPE.DOOR: return "Door" + " : " + str(s_type)
Things.TYPE.EXTRA: return null
# match s_type:
# 1: return "Action point : " + str(s_type)
# 2: return "Light : " + str(s_type)
return "Unknown"

func _on_thing_portrait_mouse_entered(nodeId):
# Don't display data if something is selected
if is_instance_valid(oInspector.inspectingInstance) == true:
Expand All @@ -243,7 +207,7 @@ func _on_thing_portrait_mouse_entered(nodeId):
var value = null

# Name
value = retrieve_thing_name(portraitThingType, portraitSubtype)
value = Things.fetch_name(portraitThingType, portraitSubtype)
if value != null:
oThingListData.add_item(str(value),"")

Expand All @@ -253,6 +217,19 @@ func _on_thing_portrait_mouse_entered(nodeId):
if value != null:
oThingListData.add_item(str(value),"")

func retrieve_subtype_value(t_type, s_type):
match t_type:
Things.TYPE.NONE: return "None" + " : " + str(s_type)
Things.TYPE.OBJECT: return "Object" + " : " + str(s_type)
Things.TYPE.CREATURE: return "Creature" + " : " + str(s_type)
Things.TYPE.EFFECTGEN: return "EffectGen" + " : " + str(s_type)
Things.TYPE.TRAP: return "Trap" + " : " + str(s_type)
Things.TYPE.DOOR: return "Door" + " : " + str(s_type)
Things.TYPE.EXTRA: return null
# match s_type:
# 1: return "Action point : " + str(s_type)
# 2: return "Light : " + str(s_type)
return "Unknown"

# Fixes an obscure issue where it would continue to show what you've highlighted in the Thing Window inside of the Properties' Thing column.
#func _on_PropertiesTabs_tab_changed(tab):
Expand Down

0 comments on commit eb52484

Please sign in to comment.