/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
Copyright 2024 nokoe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
pub mod demands;
use crate::entity::{construct_entity, Entities, EntityDecl};
use anyhow::{anyhow, bail, Result};
use demands::generate_demands;
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
Gamedata, ItemIndex, MapMetadata, Recipe, TileIndex,
};
use serde::{Deserialize, Serialize};
use std::{
collections::{HashMap, HashSet},
fs::File,
path::PathBuf,
str::FromStr,
sync::{Mutex, RwLock},
};
use tokio::fs::read_to_string;
#[derive(Debug, Deserialize, Serialize, Clone, Copy, Default)]
#[serde(rename_all = "snake_case")]
pub enum Action {
#[default]
Never,
Passive,
Active,
Instant,
Demand,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RecipeDecl {
#[serde(default)]
tile: Option,
#[serde(default)]
inputs: Vec,
#[serde(default)]
outputs: Vec,
#[serde(default)]
action: Action,
#[serde(default)]
warn: bool,
#[serde(default)]
revert_duration: Option,
#[serde(default)]
duration: Option,
#[serde(default)]
points: Option,
}
#[derive(Debug, Clone, Deserialize)]
pub struct InitialMap {
map: Vec,
tiles: HashMap,
#[serde(default)]
items: HashMap,
collider: Vec,
walkable: Vec,
chef_spawn: char,
customer_spawn: char,
#[serde(default)]
entities: Vec,
#[serde(default)]
tile_entities: HashMap,
#[serde(default)]
score_baseline: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DemandDecl {
from: String,
to: Option,
duration: f32,
points: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Demand {
pub from: ItemIndex,
pub to: Option,
pub duration: f32,
pub points: i64,
}
#[derive(Debug,Clone, Default)]
#[rustfmt::skip]
pub struct Serverdata {
pub demands: Vec,
pub spec: String,
pub initial_map: HashMap)>,
pub chef_spawn: Vec2,
pub customer_spawn: Vec2,
pub score_baseline: i64,
}
#[derive(Debug, Deserialize, Default)]
pub struct DataIndex {
pub maps: HashMap,
pub recipes: HashSet,
}
pub static DATA_DIR: Mutex