Skip to content

Commit

Permalink
6.2.0 - Add load_data_by_* (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ithinkandicode authored Mar 2, 2023
2 parents 1cc4372 + 9b57d8b commit 77a4e10
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
57 changes: 51 additions & 6 deletions root/mods-unpacked/Darkly77-ContentLoader/content_loader.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class_name ContentLoader
extends Node

var ContentData = load("res://mods-unpacked/Darkly77-ContentLoader/content_data.gd").new()
const CLOADER_LOG = "Darkly77-ContentLoader"

# Content added via ContentLoader is added via `_install_data`, called in:
Expand Down Expand Up @@ -47,8 +46,8 @@ var lookup_data_bymod = {}
# Main
# =============================================================================

# Helper method available to mods
func load_data(mod_data_path, mod_name:String = "UnspecifiedAuthor-UnspecifiedModName"):
# Add content via a ContentData resource (.tres file)
func load_data(mod_data_path: String, mod_name: String = "UnspecifiedAuthor-UnspecifiedModName"):
var from_mod_text = ""
if mod_name != "":
from_mod_text = " (via "+ mod_name +")"
Expand All @@ -61,6 +60,55 @@ func load_data(mod_data_path, mod_name:String = "UnspecifiedAuthor-UnspecifiedMo

var mod_data = load(mod_data_path)

_add_mod_data(mod_data, mod_name)


# Add content via a dictionary.
# Note that you'll need to have created textures from any images on disk (you
# can use Brotils for this, via `brotils_create_texture_from_image_path`)
# Supports passing a dictionary with a single key, eg:
# var content_data_dictionary = { "items": [] }
# @since 6.2.0
func load_data_by_dictionary(content_data_dict: Dictionary, mod_name: String = "UnspecifiedAuthor-UnspecifiedModName"):
var valid_keys := [
"items", # ItemData
"characters", # CharacterData
"weapons", # WeaponData
"sets", # SetData
"challenges", # ChallengeData / ExpandedChallengeData
"upgrades", # UpgradeData
"consumables", # ConsumableData
"elites", # Enemydata
"difficulties", # DifficultyData
"debug_items", # ItemData
"debug_weapons", # WeaponData
]

var mod_data = load("res://mods-unpacked/Darkly77-ContentLoader/content_data.gd").new()

for key in valid_keys:
if content_data_dict.has(key):
mod_data[key] = content_data_dict[key]

_add_mod_data(mod_data, mod_name)


# Load content from an instance of ContentData. Mods can't use global classes,
# so you need to load the class before you create a new instance of it, eg:
# var content_data = load("res://mods-unpacked/Darkly77-ContentLoader/content_data.gd").new()
# Note: There may be an issue with adding things to the empty arrays of a new
# ContentData instance, and this can cause your content to be added to every
# array. To fix this, duplicate your empty arrays before adding to them.
# Search for `debug_items.duplicate` in the code below to see how this is done
func load_data_by_content_data(content_data, mod_name: String = "UnspecifiedAuthor-UnspecifiedModName"):
_add_mod_data(content_data, mod_name)


# Private
# =============================================================================

# Adds mod data to the local variables
func _add_mod_data(mod_data, mod_name: String = "UnspecifiedAuthor-UnspecifiedModName"):
custom_items.append_array(mod_data.items)
custom_weapons.append_array(mod_data.weapons)
custom_characters.append_array(mod_data.characters)
Expand All @@ -87,9 +135,6 @@ func load_data(mod_data_path, mod_name:String = "UnspecifiedAuthor-UnspecifiedMo
# ModLoaderUtils.log_debug(str("weapon.my_id -> ", weapon.my_id), CLOADER_LOG)


# Private
# =============================================================================

# Save data to the lookup dictionary
func _save_to_lookup(mod_data:Resource, mod_name:String = "UnspecifiedAuthor-UnspecifiedModName"):
# Create a key for this mod in the _bymod dictionary, if it doesn't exist yet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends "res://singletons/progress_data.gd"
extends "res://singletons/debug_service.gd"

# We're extending progress_data here because we need the game to finish loading
# its data before we can add items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends "res://ui/menus/ingame/ingame_main_menu.gd"

func init() -> void:
.init()
2 changes: 1 addition & 1 deletion root/mods-unpacked/Darkly77-ContentLoader/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ContentLoader",
"namespace": "Darkly77",
"version_number": "6.1.0",
"version_number": "6.2.0",
"description": "Helper for mods to add new items, weapons, characters and challenges",
"website_url": "https://github.com/BrotatoMods/Brotato-ContentLoader",
"dependencies": [
Expand Down
7 changes: 5 additions & 2 deletions root/mods-unpacked/Darkly77-ContentLoader/mod_main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ func _ready():
func _install_extensions(modLoader):
# DEFERRED SETUP
# This runs ContentLoader._install_data(), but running that func needs to be
# deferred until after progress_data has finished setting vanilla things up
modLoader.install_script_extension(ext_dir + "singletons/progress_data.gd")
# deferred until after progress_data has finished setting vanilla things up.
# Note: Originally, this extended progress_data, but was changed to the
# last autoload (DebugService/debug_service) to allow other mods to also
# wait for ProgressData (or ItemService) to be ready first
modLoader.install_script_extension(ext_dir + "singletons/debug_service.gd")


# Add ContentLoader as a child of this node (which itself is a child of ModLoader)
Expand Down

0 comments on commit 77a4e10

Please sign in to comment.