Created
May 7, 2020 17:52
-
-
Save ImaginaryDevelopment/138bcf1e7f223b23f5b8c5f8de78d629 to your computer and use it in GitHub Desktop.
wurm_food-knowledge.py
This file contains 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
module Cereal = | |
// importing a namespace from a referenced package | |
open Newtonsoft.Json | |
open Newtonsoft.Json.Linq | |
let serialize value = JsonConvert.SerializeObject(value) | |
let deserialize<'t>(raw:string) = JsonConvert.DeserializeObject<'t>(raw) | |
let read (x:string) = System.IO.File.ReadAllText(x) | |
open Cereal | |
let MAX_INGREDIENT_ID = 138 | |
// structural equality and hashing | |
// is built-in for records in F# | |
type NameValueModel = {Name:string; Value:int} | |
with | |
static member from_json x = deserialize<NameValueModel> x | |
member x.to_json = Cereal.serialize x | |
// A model for a cooking container, eg a frying pan | |
type Container = NameValueModel | |
// A model for a cooker, eg an oven | |
type Cooker = NameValueModel | |
// A model for the display categories for a UI. | |
// :param name: The category display and key name | |
// :param id: The display id, defining the order they should be displayed | |
type Category = NameValueModel | |
// Represents an base ingredient in a recipe, without considering preparedness such as "chopped". | |
type Ingredient = { | |
name:string | |
id:int | |
group_id:int | |
combine_id:int | |
categories:string list | |
} | |
with | |
static member from_json x = deserialize<Ingredient> x | |
member x.to_json = Cereal.serialize x | |
type Rarity = | |
| Normal | |
| Rare | |
| Supreme | |
| Fantastic | |
type SkillAffinity = NameValueModel | |
type PreparationMethod = NameValueModel | |
let getLabel = | |
function | |
| Normal -> "normal" | |
| Rare -> "rare" | |
| Supreme -> "supreme" | |
| Fantastic -> "fantastic" | |
type LoadParams = { | |
container_file:string | |
cooker_file:string | |
category_file:string | |
ingredient_file:string | |
preparation_file:string | |
rarity_file:string | |
skill_affinity_file:string | |
} | |
let defaultLoadParams = { | |
container_file = "container.json" | |
cooker_file = "cookers.json" | |
category_file = "category.json" | |
ingredient_file = "ingredient.json" | |
preparation_file = "preparation.json" | |
rarity_file = "rarity.json" | |
skill_affinity_file = "skill.json" | |
} | |
type KnowledgeBase = { | |
containers: Map<string,Container> | |
cookers: Map<string, Cooker> | |
categories: Map<string, Category> | |
ingredients: Map<string, Ingredient> | |
preparation_methods: Map<string,PreparationMethod> | |
} | |
with | |
static member | |
load_from_json loadParams = | |
let readMap fn : Map<string,_> = read fn |> deserialize | |
{ | |
containers = readMap loadParams.container_file | |
cookers = readMap loadParams.cooker_file | |
categories = readMap loadParams.category_file | |
ingredients = readMap loadParams.ingredient_file | |
preparation_methods = readMap loadParams.preparation_file | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment