Logo

Braindead.bzh

Game Dev Hobbyist

A blog about my game dev hobby and various stuff.

Menu
Logo

Braindead.bzh

Game Dev Hobbyist

A blog about my game dev hobby and various stuff.

User data

Overview

There are many ways you might want to save user data, in binary, in XML or in JSON, locally or online. CardEngine cannot offer all this possibilities out-of-the-box. Instead CardEngine has interfaces which make it easier to adapt it to your needs. At the moment, there is only one interface to manage the player's stores.

UDStores

Class: res://user_data/ud_stores.gd (source)

This class offers the following functions, accessible through the UserStores singleton:

  • saved_stores() returns a Dictionary containing the saved stores with IDs as keys and names as values
  • load_store(ID, AbstractStore) loads the saved store with the given ID into the given store
  • save(ID, name, AbstractStore) save the store data with the given ID and name

This interface comes with a default implementation bases on the ConfigFile built-in Godot class. However, the following functions can be customized to your needs:

  • _get_stores()
# Retrieves the list of all saved stores
# Customized this function to your need
# Returns a Dictionary:
# {
#   "<store id>": "<store name>",
#   "<store id>": "<store name>",
#   "<store id>": "<store name>",
#   ...
# }
func _get_stores() -> Dictionary:
  ...
  • _get_store(ID)
# Retrieves the store with the given ID
# Customized this function to your need
# Returns a Dictionary:
# {
#   "id": "<store id>",
#   "name": "<store name>",
#   "cards": [
#     {"id": "<card id>", "source": "<database id>},
#     {"id": "<card id>", "source": "<database id>},
#     {"id": "<card id>", "source": "<database id>},
#     ...
#   ]
# }
func _get_store(id: String) -> Dictionary:
  ...
  • _post_store(ID, name, Array)
# Saves a store with the given ID, name and cards
# Customized this function to your need
# Cards Array:
# [
#   {"id": "<card id>", "source": "<database id>},
#   {"id": "<card id>", "source": "<database id>},
#   {"id": "<card id>", "source": "<database id>},
#   ...
# ]
func _post_store(id: String, name: String, cards: Array) -> void:
  ...