From 0559712f8626b8c7d06dbc3b56c6db425fd72e01 Mon Sep 17 00:00:00 2001
From: Loobinex <Loobinex@users.noreply.github.com>
Date: Mon, 19 Aug 2024 15:50:01 +0200
Subject: [PATCH 1/2] Hero gates and spellbooks dynamically filled

---
 Autoload/Things.gd      | 23 +++--------------
 Scenes/CfgLoader.gd     | 55 ++++++++++++++++++++++-------------------
 Scenes/Instances.gd     |  2 +-
 Scenes/ReadData.gd      |  4 +--
 Scenes/ThingInstance.gd |  2 +-
 5 files changed, 36 insertions(+), 50 deletions(-)

diff --git a/Autoload/Things.gd b/Autoload/Things.gd
index 583269e9..6e95d626 100644
--- a/Autoload/Things.gd
+++ b/Autoload/Things.gd
@@ -168,6 +168,7 @@ var GENRE_TO_TAB = {
 	"TREASURE_HOARD": TAB_GOLD,
 	"VALUABLE": TAB_GOLD,
 	"WORKSHOPBOX": TAB_BOX,
+	"HEROGATE": TAB_ACTION,
 }
 
 
@@ -203,26 +204,8 @@ var LIST_OF_GOLDPILES = [
 ]
 
 
-var LIST_OF_SPELLBOOKS = [
-SPELLBOOK.HAND,
-SPELLBOOK.SLAP,
-SPELLBOOK.POSSESS,
-SPELLBOOK.IMP,
-SPELLBOOK.SIGHT,
-SPELLBOOK.SPEED,
-SPELLBOOK.OBEY,
-SPELLBOOK.CALL_TO_ARMS,
-SPELLBOOK.CONCEAL,
-SPELLBOOK.HOLD_AUDIENCE,
-SPELLBOOK.CAVE_IN,
-SPELLBOOK.HEAL_CREATURE,
-SPELLBOOK.LIGHTNING,
-SPELLBOOK.PROTECT,
-SPELLBOOK.CHICKEN,
-SPELLBOOK.DISEASE,
-SPELLBOOK.ARMAGEDDON,
-SPELLBOOK.DESTROY_WALLS,
-]
+var LIST_OF_SPELLBOOKS = [ ]
+var LIST_OF_HEROGATES = [ ]
 
 enum SPELLBOOK {
 	HAND = 11
diff --git a/Scenes/CfgLoader.gd b/Scenes/CfgLoader.gd
index 5a0fc0eb..525607cb 100644
--- a/Scenes/CfgLoader.gd
+++ b/Scenes/CfgLoader.gd
@@ -100,34 +100,37 @@ func load_objects_data(cfg): # 10ms
 		if section.begins_with("object"):
 			var id = int(section)
 			if id == 0: continue
-			if id >= 136 or id in [100, 101, 102, 103, 104, 105]: # Dummy Boxes should be overwritten
-				var objSection = cfg[section]
-				var newName
-				var animID
-				var newSprite
-				var newEditorTab
-				var newGenre
+			var objSection = cfg[section]
+			var newName
+			var animID
+			var newSprite
+			var newEditorTab
+			var newGenre
+			
+			if Things.DATA_OBJECT.has(id) == true:
+				newName = objSection.get("Name", Things.DATA_OBJECT[id][Things.NAME_ID])
 				
-				if Things.DATA_OBJECT.has(id) == true:
-					newName = objSection.get("Name", Things.DATA_OBJECT[id][Things.NAME_ID])
-					
-					animID = objSection.get("AnimationID")
-					newSprite = get_sprite(animID, newName)
-					if newSprite == null:
-						newSprite = Things.DATA_OBJECT[id][Things.SPRITE]
-					
-					newGenre = objSection.get("Genre")
-					newEditorTab = Things.GENRE_TO_TAB.get(newGenre, Things.DATA_OBJECT[id][Things.EDITOR_TAB])
-				else:
-					newName = objSection.get("Name", "UNDEFINED_NAME")
-					
-					animID = objSection.get("AnimationID")
-					newSprite = get_sprite(animID, newName)
-					
-					newGenre = objSection.get("Genre")
-					newEditorTab = Things.GENRE_TO_TAB.get(newGenre, Things.TAB_DECORATION)
+				animID = objSection.get("AnimationID")
+				newSprite = get_sprite(animID, newName)
+				if newSprite == null:
+					newSprite = Things.DATA_OBJECT[id][Things.SPRITE]
+				
+				newGenre = objSection.get("Genre")
+				newEditorTab = Things.GENRE_TO_TAB.get(newGenre, Things.DATA_OBJECT[id][Things.EDITOR_TAB])
+				if newGenre == "SPELLBOOK":
+					Things.LIST_OF_SPELLBOOKS.append(id)
+				if newGenre == "HEROGATE":
+					Things.LIST_OF_HEROGATES.append(id)
+			else:
+				newName = objSection.get("Name", "UNDEFINED_NAME")
+				
+				animID = objSection.get("AnimationID")
+				newSprite = get_sprite(animID, newName)
 				
-				Things.DATA_OBJECT[id] = [newName, newSprite, newEditorTab]
+				newGenre = objSection.get("Genre")
+				newEditorTab = Things.GENRE_TO_TAB.get(newGenre, Things.TAB_DECORATION)
+			
+			Things.DATA_OBJECT[id] = [newName, newSprite, newEditorTab]
 
 
 var keeperfx_edited_slabs = [Slabs.GEMS] # This is to help with backwards compatibility for previous keeperfx versions that don't have these edits.
diff --git a/Scenes/Instances.gd b/Scenes/Instances.gd
index c456115e..fd8a7c11 100644
--- a/Scenes/Instances.gd
+++ b/Scenes/Instances.gd
@@ -259,7 +259,7 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla
 			id.parentTile = 65535 # "None"
 			id.orientation = oPlacingSettings.orientation
 			
-			if id.subtype == 49: # Hero Gate
+			if id.subtype in Things.LIST_OF_HEROGATES: # Hero Gate
 				id.herogateNumber = get_free_hero_gate_number() #originalInstance.herogateNumber
 			elif id.subtype == 133: # Mysterious Box
 				id.boxNumber = oPlacingSettings.boxNumber
diff --git a/Scenes/ReadData.gd b/Scenes/ReadData.gd
index 8050badc..13807139 100644
--- a/Scenes/ReadData.gd
+++ b/Scenes/ReadData.gd
@@ -351,7 +351,7 @@ func read_tng(buffer):
 		match id.thingType:
 			Things.TYPE.OBJECT:
 				id.parentTile = id.data11_12
-				if id.subtype == 49: # Hero Gate
+				if id.subtype in Things.LIST_OF_HEROGATES: # Hero Gate
 					id.herogateNumber = id.data14
 				elif id.subtype == 133: # Mysterious Box
 					id.boxNumber = id.data14
@@ -415,7 +415,7 @@ func read_tngfx(buffer):
 			match id.thingType:
 				Things.TYPE.OBJECT:
 					id.parentTile = c.get_value(section, "ParentTile")
-					if id.subtype == 49: # Hero Gate
+					if id.subtype in Things.LIST_OF_HEROGATES: # Hero Gate
 						id.herogateNumber = c.get_value(section, "HerogateNumber")
 					elif id.subtype == 133: # Mysterious Box
 						id.boxNumber = c.get_value(section, "CustomBox")
diff --git a/Scenes/ThingInstance.gd b/Scenes/ThingInstance.gd
index a49a86bd..b48ec7f9 100644
--- a/Scenes/ThingInstance.gd
+++ b/Scenes/ThingInstance.gd
@@ -71,7 +71,7 @@ func _enter_tree():
 				add_to_group("TreasuryGold")
 			elif subtype in Things.LIST_OF_SPELLBOOKS:
 				add_to_group("Spellbook")
-			elif subtype == 49:
+			elif subtype in Things.LIST_OF_HEROGATES:
 				add_to_group("HeroGate")
 				yield(get_tree(),'idle_frame')
 				if oActionPointList:

From 035ab32a077960db539890324431291fcdbacf72 Mon Sep 17 00:00:00 2001
From: Loobinex <Loobinex@users.noreply.github.com>
Date: Mon, 19 Aug 2024 19:08:30 +0200
Subject: [PATCH 2/2] Fixed spellicons

---
 Scenes/CfgLoader.gd | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/Scenes/CfgLoader.gd b/Scenes/CfgLoader.gd
index 525607cb..07501cf1 100644
--- a/Scenes/CfgLoader.gd
+++ b/Scenes/CfgLoader.gd
@@ -94,6 +94,32 @@ func start(mapPath):
 	
 	oCustomSlabSystem.load_unearth_custom_slabs_file()
 
+var LIST_OF_OBJECTS_WITH_HARDCODED_SPRITES = [
+"SPELLBOOK_HOE",
+"SPELLBOOK_IMP",
+"SPELLBOOK_OBEY",
+"SPELLBOOK_SLAP",
+"SPELLBOOK_SOE",
+"SPELLBOOK_CTA",
+"SPELLBOOK_CAVI",
+"SPELLBOOK_HEAL",
+"SPELLBOOK_HLDAUD",
+"SPELLBOOK_LIGHTN",
+"SPELLBOOK_SPDC",
+"SPELLBOOK_PROT",
+"SPELLBOOK_CONCL",
+"SPELLBOOK_DISEASE",
+"SPELLBOOK_CHKN",
+"SPELLBOOK_DWAL",
+"SPELLBOOK_TBMB",
+"SPELLBOOK_ARMG",
+"SPELLBOOK_POSS",
+"SPELLBOOK_RBND",
+"SPELLBOOK_FRZ",
+"SPELLBOOK_SLOW",
+"SPELLBOOK_FLGT",
+"SPELLBOOK_VSN",
+]
 
 func load_objects_data(cfg): # 10ms
 	for section in cfg:
@@ -112,7 +138,7 @@ func load_objects_data(cfg): # 10ms
 				
 				animID = objSection.get("AnimationID")
 				newSprite = get_sprite(animID, newName)
-				if newSprite == null:
+				if newSprite == null or newName in LIST_OF_OBJECTS_WITH_HARDCODED_SPRITES:
 					newSprite = Things.DATA_OBJECT[id][Things.SPRITE]
 				
 				newGenre = objSection.get("Genre")
@@ -123,7 +149,6 @@ func load_objects_data(cfg): # 10ms
 					Things.LIST_OF_HEROGATES.append(id)
 			else:
 				newName = objSection.get("Name", "UNDEFINED_NAME")
-				
 				animID = objSection.get("AnimationID")
 				newSprite = get_sprite(animID, newName)