use crate::hash::HashMap
struct RemovedState {
actors: HashMap<String, bool>,
entities: Vec<String>,
components: HashMap<String, HashMap<String, bool>>,
}
struct UpdatedState {
components: HashMap<String, HashMap<String, bool>>,
}
struct CreatedState {
actors: HashMap<String, bool>,
entities: Vec<String>,
components: HashMap<String, HashMap<String, bool>>,
inputs: HashMap<String, Vec<i32>>,
}
struct PendingContext {
pending: Option<Pending>,
}
struct Pending {
removed: RemovedState,
updated: UpdatedState,
created: CreatedState,
}
impl Pending {
fn new() -> Self {
Self {
removed: RemovedState {
actors: HashMap::new(),
entities: Vec::new(),
components: HashMap::new(),
},
updated: UpdatedState {
components: HashMap::new(),
},
created: CreatedState {
actors: HashMap::new(),
entities: Vec::new(),
components: HashMap::new(),
inputs: HashMap::new(),
},
}
}
fn actor_input(&mut self, id: String, newindex: i32) {
self.created.inputs.entry(id).or_insert(Vec::new()).push(newindex);
}
fn change_component(&mut self, pending_type: String, id: String, key: String) {
self.upsert_component(pending_type, id, key);
}
fn create_entity(&mut self, id: String) {
self.created.entities.push(id);
}
fn remove_actor(&mut self, id: String) {
self.removed.actors.insert(id, true);
}
fn remove_component(&mut self, id: String, key: String) {
self.removed.components.entry(id).or_insert(HashMap::new()).insert(key, true);
}
fn remove_entity(&mut self, id: String) {
self.removed.entities.push(id);
}
fn reset(&mut self) {
*self = Self::new();
}
fn spawn_actor(&mut self, id: String) {
self.created.actors.insert(id, true);
}
fn upsert_component(&mut self, pending_type: String, id: String, key: String) {
let pending = if pending_type == "created" {
&mut self.created
} else {
&mut self.updated
};
if let Some(components) = pending.components.get_mut(&id) {
components.insert(key, true);
} else {
let mut new_components = HashMap::new();
new_components.insert(key, true);
pending.components.insert(id, new_components);
}
}
}
struct WithPending {
pending: Pending,
}
impl WithPending {
fn new(context: ContextWithPending | ContextWithPendingAndSymbols) -> Self {
let pending = context.pending.unwrap_or_else(|| Pending::new());
Self { pending }
}
fn reset_pending(&mut self) {
self.pending.reset();
}
}
struct PendingWithSymbols {
pending: Pending,
symbols: Vec<(String, i32)>,
}
impl PendingWithSymbols {
fn new() -> Self {
Self {
pending: Pending::new(),
symbols: Vec::new(),
}
}
fn add_symbol(&mut self, symbol_tuple: (String, i32)) {
self.symbols.push(symbol_tuple);
}
fn replace_symbols(&mut self, symbols: Vec<(String, i32)>) {
self.symbols = symbols;
}
}
fn main() {
let pending_with_symbols = PendingWithSymbols::new();
}