-
Notifications
You must be signed in to change notification settings - Fork 58
Other Components
Aside from MetSysGame, the template provides some misc scripts and scenes.
Saves and loads game data. Automatically includes MetSys save data and allows to load custom Resources in a safe way. To use the manager, you need to instantiate the script directly using new()
(it's located in Template/Scripts/SaveManager.gd
inside addon's folder). You can store data using manager.set_data(field, value)
, which will store the value in the internal Dictionary under the given key. You can store a custom Resource using manager.store_resource(res, field)
. It will store Resource's properties as Dictionary, so it avoids the usual security risk. The field is optional, if you don't provide it, the Resource's properties will be merged with other data in the Dictionary (not recommended when storing multiple resources). To save the data, use manager.save_as_text(path)
or manager.save_as_binary(path)
.
const SaveManager = preload("res://addons/MetroidvaniaSystem/Template/Scripts/SaveManager.gd")
func save():
var saver := SaveManager.new()
saver.set_data("current_room", MetSys.get_current_room_name())
saver.store_resource(player.stats, "player_stats")
saver.save_as_text("user://save.sav")
Loading game data involves the same steps, but in reverse and different methods. Use manager.load_from_text()
or manager.load_from_binar()
to load your data. Then you can get values using manager.get_value(field, default)
(default
is optional, the method returns null
if the value does not exist). Use manager.retrieve_resource(res, field)
to load the data into an existing resource. The manager will iterate resource's properties and load matching data. The field
must match the one you provided for store_resource()
. The manager will automatically assign MetSys data when loading.
func load():
var loader := SaveManager.new()
loader.load_from_text("user://save.sav")
loader.retrieve_resource(player.stats, "player_stats")
change_map_to(loader.get_value("current_room"))
If you can't deal with files (e.g. due to using some cloud system or other services), you can use manager.save_as_string()
and manager.load_from_string(string)
to manage the data using raw Strings.
A Control-based node that draws part of the map. Comes with a few properties that allow automatic position tracking, smooth scrolling, displaying player location, specifying the center point and layer. area
property specifies the size of minimap, in cells. The node can be used both as a minimap or in a map screen. When using as a minimap, odd area values are recommended, so that the center is clearly defined. In case of doubt, the properties come with their own documentation.
Instantiate the minimap from Template/Nodes/Minimap.tscn
inside the addon's folder. Like in case of MapView, the Minimap elements can appear at up to +3 z-index.