43 lines
770 B
GDScript
43 lines
770 B
GDScript
class_name Recipe
|
|
|
|
enum Id {
|
|
NULL,
|
|
BAKED_POTATO,
|
|
}
|
|
|
|
# Data storage
|
|
static var RECIPES = []
|
|
|
|
# Initializer
|
|
static func defineRecipe(params:Dictionary) -> Dictionary:
|
|
assert(params.has("id"))
|
|
assert(params.has("handle"))
|
|
|
|
var recipe = {
|
|
"id": params["id"],
|
|
"handle": params.get("handle"),
|
|
}
|
|
|
|
RECIPES.insert(params["id"], recipe)
|
|
return recipe
|
|
|
|
# Instances
|
|
static var RECIPE_NULL = defineRecipe({
|
|
"id": Id.NULL,
|
|
"handle": "unknown"
|
|
})
|
|
|
|
static var BAKED_POTATO = defineRecipe({
|
|
"id": Id.BAKED_POTATO,
|
|
"handle": "baked_potato"
|
|
})
|
|
|
|
# Getters
|
|
static func getData(id:int) -> Dictionary:
|
|
if RECIPES.size() <= id || id < 0:
|
|
return RECIPE_NULL
|
|
return RECIPES[id]
|
|
|
|
static func getRecipeHandle(id:Id) -> String:
|
|
return getData(id)["handle"]
|