Last active
January 2, 2024 18:05
-
-
Save nightblade9/414d8c6dd34f600d538c99acac15c4d2 to your computer and use it in GitHub Desktop.
DLC loading in Godot (GDscript 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
### A buncha DLC stuff that's not easy without reflection | |
var custom_levels = {} # W1L2 => load(...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func _load_dlcs(): | |
# maybe add some DLCs later. | |
if CoreFeatures.load_dlcs: | |
# TODO: replace with a fetch of files from disk | |
var known_dlcs = {"Origins": "Origins/Origins.pck"} | |
for dlc_name in known_dlcs.keys(): | |
var dlc = known_dlcs[dlc_name] | |
var full_path = "res://DLCs/%s" % dlc | |
if File.new().file_exists(full_path): | |
var is_successful = ProjectSettings.load_resource_pack(full_path) | |
var status_message = "Loaded" if is_successful else "Failed to load" | |
print("%s %s DLC from %s" % [status_message, dlc_name, full_path]) | |
_dlcs_label.text += "%s DLC\n" % dlc_name | |
# This sucks. Lack of reflection sucks. IDK how else to do this without brute-forcing. | |
# Figures out what levels are in the DLC packs, and saves instances in a dictionray. | |
var base_level_path = "res://DLCs/%s/Levels/" % dlc_name | |
for world_number in range(1, 10): | |
for level_number in range(1, 10): | |
var level_id = "W%sL%s" % [world_number, level_number] | |
var level_path = "%s/%s.tscn" % [base_level_path, level_id] | |
if ResourceLoader.exists(level_path): | |
print("Loading %s from %s" % [dlc_name, level_id]) | |
# Overrides other DLCs, core levels, etc. | |
DlcContent.custom_levels[level_id] = load(level_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment