From 1de820dfccc6b45c70146da06bdd6827eb1c00ef Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 18 Apr 2020 20:58:43 +0200 Subject: [PATCH] Now the game pretty much supports modding. MainScene will now look through the project opening all files named game_module.tres and in alphabetic order of their resource_path if exist it calls load_module on them. ESS's resourcedb is now created by MainScene, and it's the static type, with id remapping on. Append your resourcedbs into it. See game_module.gd. Also updated HEADS to grab the latest ESS. --- HEADS | 2 +- game/data/game_module.tres | 9 +++++ game/player/bs_entity_spawner.gd | 2 +- game/project.godot | 6 +++ game/scenes/CharacterSelectorMenu.gd | 8 ++++ game/scenes/MainScene.gd | 49 ++++++++++++++++++++++++- game/scripts/game_modules/GameModule.gd | 12 ++++++ game/ui/actionbars/ActionBarEntry.gd | 5 ++- game/voxelman/world/TVVoxelWorld.gd | 2 +- 9 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 game/data/game_module.tres create mode 100644 game/scripts/game_modules/GameModule.gd diff --git a/HEADS b/HEADS index ec248ff9..60272772 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "50582446ad13a7ce034bdd8695409bf26c1abac3", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "9d946f1623b9cb57b2e1d9681ac3b7f7e7b746d4"}, "entity_spell_system": {"master": "6c9bea09bc91bc62c0bb2493b1b5b2e1cc88bd6c"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "23c4321d71927a0e2d08b5d19fc4c5bb8242e7d2"}, "texture_packer": {"master": "b29b499adf570aa7f85af69ef080ff0d5e04afae"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "4ee946963a16bbfdb4dbb5df52134d22aa168041"}, "procedural_animations": {"master": "9ae56c17230ba9c6160777650b2b89eecdc8df9e"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}} \ No newline at end of file +{"engine": {"3.2": "50582446ad13a7ce034bdd8695409bf26c1abac3", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "9d946f1623b9cb57b2e1d9681ac3b7f7e7b746d4"}, "entity_spell_system": {"master": "b5ed3b16c8ec7bc3fe6147e67b59dc7ffb64e88c"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "23c4321d71927a0e2d08b5d19fc4c5bb8242e7d2"}, "texture_packer": {"master": "b29b499adf570aa7f85af69ef080ff0d5e04afae"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "4ee946963a16bbfdb4dbb5df52134d22aa168041"}, "procedural_animations": {"master": "9ae56c17230ba9c6160777650b2b89eecdc8df9e"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}} \ No newline at end of file diff --git a/game/data/game_module.tres b/game/data/game_module.tres new file mode 100644 index 00000000..22b8a710 --- /dev/null +++ b/game/data/game_module.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://scripts/game_modules/GameModule.gd" type="Script" id=1] +[ext_resource path="res://data/resource_db.tres" type="ESSResourceDBFolders" id=2] + + +[resource] +script = ExtResource( 1 ) +resource_db = ExtResource( 2 ) diff --git a/game/player/bs_entity_spawner.gd b/game/player/bs_entity_spawner.gd index c9c2a098..62cb2ac1 100644 --- a/game/player/bs_entity_spawner.gd +++ b/game/player/bs_entity_spawner.gd @@ -117,7 +117,7 @@ func load_player(file_name : String, position : Vector3, network_owner : int) -> func spawn_player_for_menu(class_id : int, name : String, parent : Node) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() - var cls : EntityData = ESS.get_player_character_data(class_id) + var cls : EntityData = ESS.resource_db.get_entity_data(class_id) var class_profile : ClassProfile = ProfileManager.getc_player_profile().get_class_profile(class_id) var level : int = 1 diff --git a/game/project.godot b/game/project.godot index 65085cd1..9b427863 100644 --- a/game/project.godot +++ b/game/project.godot @@ -184,6 +184,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://steering_ai_framework/GSAIUtils.gd" }, { +"base": "Resource", +"class": "GameModule", +"language": "GDScript", +"path": "res://scripts/game_modules/GameModule.gd" +}, { "base": "ItemTemplate", "class": "ItemTemplateGD", "language": "GDScript", @@ -295,6 +300,7 @@ _global_script_class_icons={ "GSAISteeringBehavior": "", "GSAITargetAcceleration": "", "GSAIUtils": "", +"GameModule": "", "ItemTemplateGD": "", "LayeredTextureMaker": "", "Main": "", diff --git a/game/scenes/CharacterSelectorMenu.gd b/game/scenes/CharacterSelectorMenu.gd index 3df5c09f..480a5a28 100644 --- a/game/scenes/CharacterSelectorMenu.gd +++ b/game/scenes/CharacterSelectorMenu.gd @@ -85,6 +85,14 @@ func refresh(): continue var display : Entity = ESS.entity_spawner.spawn_display_player(file_name, player_display_container_node.get_path()) + + var entity_data : EntityData = ESS.get_resource_db().get_entity_data(display.characterclass_id) + + if entity_data == null: + print("EntityData not found!") + display.queue_free() + continue + #player_display_container_node.add_child(display) #display.owner = player_display_container_node diff --git a/game/scenes/MainScene.gd b/game/scenes/MainScene.gd index b0744c3d..b6a79a65 100644 --- a/game/scenes/MainScene.gd +++ b/game/scenes/MainScene.gd @@ -36,13 +36,54 @@ var _loading_screen : Node var current_scene : Node var current_character_file_name : String = "" +var _modules : Array + func _ready() -> void: _loading_screen = get_node(loading_screen_path) ProfileManager.load() - ESS.load_all() + ESS.load_entity_spawner() + ESS.resource_db = ESSResourceDBStatic.new() +# ESS.resource_db = ESSResourceDBFolders.new() + ESS.resource_db.remap_ids = true +# ESS.load_all() + + initialize_modules() switch_scene(start_scene) + +func initialize_modules() -> void: + _modules.clear() + + load_modules_at("res://") + + _modules.sort_custom(ModulePathSorter, "sort_ascending") + + for module in _modules: + if module.has_method("load_module"): + module.load_module() + +func load_modules_at(path : String) -> void: + var dir = Directory.new() + if dir.open(path) == OK: + dir.list_dir_begin() + var file_name = dir.get_next() + while file_name != "": + if file_name == "." or file_name == "..": + file_name = dir.get_next() + continue + + if dir.current_is_dir(): + load_modules_at(path + "/" + file_name) + else: + if file_name == "game_module.tres": + var res : Resource = ResourceLoader.load(path + "/" + file_name) + + _modules.append(res) + + file_name = dir.get_next() + else: + print("An error occurred when trying to access the path: " + path) func switch_scene(scene : int) -> void: if current_scene != null: @@ -110,3 +151,9 @@ func show_loading_screen() -> void: func hide_loading_screen() -> void: _loading_screen.hide() + +class ModulePathSorter: + static func sort_ascending(a, b): + if a.resource_path < b.resource_path: + return true + return false diff --git a/game/scripts/game_modules/GameModule.gd b/game/scripts/game_modules/GameModule.gd new file mode 100644 index 00000000..f663289f --- /dev/null +++ b/game/scripts/game_modules/GameModule.gd @@ -0,0 +1,12 @@ +extends Resource +class_name GameModule + +export(ESSResourceDB) var resource_db : ESSResourceDB + +func load_module(): + if resource_db != null: + resource_db.initialize() + + ESS.resource_db.add_entity_resource_db(resource_db) + +# var r : ESSResourceDB = ESS.resource_db diff --git a/game/ui/actionbars/ActionBarEntry.gd b/game/ui/actionbars/ActionBarEntry.gd index c0542d56..2378f873 100644 --- a/game/ui/actionbars/ActionBarEntry.gd +++ b/game/ui/actionbars/ActionBarEntry.gd @@ -161,7 +161,10 @@ func setup_icon() -> void: ThemeAtlas.unref_texture(icon_rect.texture) icon_rect.texture = null - var spell = ESS.get_resource_db().get_spell(button_entry.item_id) + var spell = ESS.resource_db.get_spell(button_entry.item_id) + + if spell == null: + return if spell.icon != null: icon_rect.texture = ThemeAtlas.add_texture(spell.icon) diff --git a/game/voxelman/world/TVVoxelWorld.gd b/game/voxelman/world/TVVoxelWorld.gd index 42995511..ba6619e3 100644 --- a/game/voxelman/world/TVVoxelWorld.gd +++ b/game/voxelman/world/TVVoxelWorld.gd @@ -240,4 +240,4 @@ func save() -> void: if _player == null or _player_file_name == "": return - ESS.get_ess_entity_spawner().save_player(_player, _player_file_name) + ESS.entity_spawner.save_player(_player, _player_file_name)