Prepping cooking
This commit is contained in:
42
cooking/Recipe.gd
Normal file
42
cooking/Recipe.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
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"]
|
||||
Reference in New Issue
Block a user