use std::collections::HashMap;
use serde_json;
use serde::{Deserialize, Serialize};
use crate::Either;
fn default_lang()->Vec<String>{
vec![String::from("en")]
}
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq,Eq)]
#[serde(rename_all="camelCase")]
pub enum Theme{
Dirt,
Grass,
GrassFlowers,
Ice,
Jungle,
Ocean,
PartyTime,
Stone,
}
impl Default for Theme{
fn default() -> Self {
Self::Grass
}
}
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq,Eq)]
pub struct Tutorial{
pub name: String,
pub description: String,
pub language: String,
pub file_name: String,
pub link: String,
#[serde(default)]
pub authors: Vec<String>
}
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq,Eq,Default)]
pub struct Web{
#[serde(default)]
pub options_page: Either<bool,String>,
#[serde(default="default_lang")]
pub game_info_languages: Vec<String>,
#[serde(default)]
pub theme: Theme,
#[serde(default,skip_serializing_if="Option::is_none")]
pub bug_report_page: Option<String>,
#[serde(default,skip_serializing_if="Vec::is_empty")]
pub tutorials: Vec<Tutorial>,
#[serde(default,skip_serializing_if="HashMap::is_empty")]
pub options_presets: HashMap<String,HashMap<String,serde_json::Value>>
}
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq,Eq)]
pub struct Docs{
pub apworld_description: Vec<String>,
pub web: Web,
}
impl Default for Docs{
fn default() -> Self {
Self { apworld_description: vec!["This is a manual meta page".to_string()], web: Web::default() }
}
}
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq, Eq,Default)]
pub struct Meta{
pub docs: Docs,
#[serde(default)]
pub enable_region_diagram: bool
}
#[cfg(test)]
mod test{
use crate::meta::{Meta, Theme};
#[test]
fn meta_test(){
let tv="{
\"$schema\": \"https://raw.githubusercontent.com/ManualForArchipelago/Manual/main/schemas/Manual.meta.schema.json\",\
\"_comment\": [ \"remove the _ before a non-comment/info propertie to enable it\",
\"For more info use json schemas to get a description and allowed value for every properties\",
\"https://github.com/ManualForArchipelago/Manual/blob/main/docs/resources/json-schemas-for-world-devs.md\"],
\"docs\": {
\"_comment\": [ \"For more info on the possible documentation properties check schema and/or the github\",
\"https://github.com/ArchipelagoMW/Archipelago/blob/main/docs/world%20api.md#webworld-class\"
],
\"apworld_description\": [
\"Manual games allow you to set custom check locations and custom item names that will be rolled into a multiworld.\",
\"This allows any variety of game -- PC, console, board games, Microsoft Word memes... really anything -- to be part of a multiworld randomizer.\",
\"The key component to including these games is some level of manual restriction. Since the items are not actually withheld from the player,\",
\"the player must manually refrain from using these gathered items until the tracker shows that they have been acquired or sent.\"
],
\"web\": {
\"_comment\": \"for more info check github https://github.com/ArchipelagoMW/Archipelago/blob/main/docs/world%20api.md#webworld-class\",
\"theme\": \"grass\",
\"bug_report_page\": \"https://discord.gg/T5bcsVHByx\",
\"tutorials\": [
{
\"name\": \"Multiworld Setup Guide\",
\"description\": \"A guide to setting up manual game integration for Archipelago multiworld games.\",
\"language\": \"English\",
\"file_name\": \"setup_en.md\",
\"link\": \"setup/en\",
\"_authors\": [\"Fuzzy\"],\
\"_comment\": \"if you don't include the authors it will use creator from game.json\"\
}],\
\"options_presets\": {\
\"Easy\":{\
\"Option1\": true,\
\"Option2\": \"potato\"}}}},\
\"_comment_\":\"Enable the generation of puml diagram of your apworld region and locations for debug purposes\",\
\"enable_region_diagram\": false}";
let tst: Meta = serde_json::from_str(tv).unwrap();
assert_eq!(tst.docs.apworld_description.len(),4);
assert_eq!(tst.docs.web.theme,Theme::Grass);
assert_eq!(tst.docs.web.bug_report_page,Some("https://discord.gg/T5bcsVHByx".to_string()));
assert_eq!(tst.docs.web.tutorials.len(),1);
assert_eq!(&tst.docs.web.tutorials[0].name,"Multiworld Setup Guide");
}
}