From 3918f08a54e1463a4d408145fa43ae457025e4df Mon Sep 17 00:00:00 2001 From: TCA166 Date: Tue, 14 May 2024 10:48:25 +0200 Subject: [PATCH] Made the GameStrng and Shared more opaque --- src/game_object.rs | 40 +++++++++++++++++++++- src/game_state.rs | 16 ++++----- src/structures/character.rs | 64 +++++++++++++++++------------------ src/structures/culture.rs | 6 ++-- src/structures/derived_ref.rs | 14 ++++---- src/structures/dynasty.rs | 18 +++++----- src/structures/faith.rs | 8 ++--- src/structures/lineage.rs | 2 +- src/structures/memory.rs | 6 ++-- src/structures/mod.rs | 28 +++++++++++++-- src/structures/player.rs | 6 ++-- src/structures/title.rs | 18 +++++----- 12 files changed, 143 insertions(+), 83 deletions(-) diff --git a/src/game_object.rs b/src/game_object.rs index d2e27a7..bdf6835 100644 --- a/src/game_object.rs +++ b/src/game_object.rs @@ -1,4 +1,22 @@ -use std::{collections::{hash_map, HashMap}, rc::Rc, slice, fmt::Debug}; +use std::{cell::{BorrowError, BorrowMutError, Ref, RefMut}, collections::{hash_map, HashMap}, fmt::Debug, ops::Deref, rc::Rc, slice}; + +/// A reference or a raw value. I have no clue why this isn't a standard library type. +/// A [Ref] and a raw reference are both dereferencable to the same type. +pub enum RefOrRaw<'a, T: 'a> { + Ref(Ref<'a, T>), + Raw(&'a T), +} + +impl<'a, T> Deref for RefOrRaw<'a, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + match self { + RefOrRaw::Ref(r) => r.deref(), + RefOrRaw::Raw(r) => r, + } + } +} /// A trait for objects that wrap a certain value. /// Allows us to create opaque type aliases for certain types. @@ -6,6 +24,18 @@ use std::{collections::{hash_map, HashMap}, rc::Rc, slice, fmt::Debug}; pub trait Wrapper { /// Wrap a value in the object fn wrap(t:T) -> Self; + + fn get_internal(&self) -> RefOrRaw; + + fn try_get_internal(&self) -> Result, BorrowError>; +} + +/// A trait for objects that wrap a certain value and allow mutation. +/// Allows us to create opaque type aliases for certain types. +pub trait WrapperMut { + fn get_internal_mut(&self) -> RefMut; + + fn try_get_internal_mut(&self) -> Result, BorrowMutError>; } /// A type alias for a game object id. @@ -21,6 +51,14 @@ impl Wrapper for GameString { fn wrap(t:String) -> Self { Rc::new(t) } + + fn get_internal(&self) -> RefOrRaw{ + RefOrRaw::Raw(self.as_ref()) + } + + fn try_get_internal(&self) -> Result, BorrowError> { + Ok(self.get_internal()) + } } /// A value that can be stored in a SaveFile and is held by a GameObject. diff --git a/src/game_state.rs b/src/game_state.rs index 2162950..7feb252 100644 --- a/src/game_state.rs +++ b/src/game_state.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::structures::{Character, Culture, DerivedRef, Dynasty, Faith, GameObjectDerived, Memory, Shared, Title}; -use crate::game_object::{GameId, GameObject, GameString, Wrapper}; +use crate::game_object::{GameId, GameObject, GameString, Wrapper, WrapperMut}; /// A struct representing all known game objects. /// It is guaranteed to always return a reference to the same object for the same key. @@ -80,7 +80,7 @@ impl GameState{ let char = self.get_character(character_id); if self.contract_transform.contains_key(contract_id){ let entry = self.contract_transform.get(contract_id).unwrap(); - entry.borrow_mut().init(char); + entry.get_internal_mut().init(char); } else{ let r = Shared::wrap(DerivedRef::from_derived(char)); @@ -153,7 +153,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.characters.contains_key(&key){ let c = self.characters.get(&key).unwrap().clone(); - c.borrow_mut().init(value, self); + c.get_internal_mut().init(value, self); } else{ let c = Character::from_game_object(value, self); @@ -166,7 +166,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.titles.contains_key(&key){ let t = self.titles.get(&key).unwrap().clone(); - t.borrow_mut().init(value, self); + t.get_internal_mut().init(value, self); } else{ let t = Title::from_game_object(value, self); @@ -179,7 +179,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.faiths.contains_key(&key){ let f = self.faiths.get(&key).unwrap().clone(); - f.borrow_mut().init(value, self); + f.get_internal_mut().init(value, self); } else{ let f = Faith::from_game_object(value, self); @@ -192,7 +192,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.cultures.contains_key(&key){ let c = self.cultures.get(&key).unwrap().clone(); - c.borrow_mut().init(value, self); + c.get_internal_mut().init(value, self); } else{ let c = Culture::from_game_object(value, self); @@ -205,7 +205,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.dynasties.contains_key(&key){ let d = self.dynasties.get(&key).unwrap().clone(); - d.borrow_mut().init(value, self); + d.get_internal_mut().init(value, self); } else{ let d = Dynasty::from_game_object(value, self); @@ -218,7 +218,7 @@ impl GameState{ let key = value.get_name().parse::().unwrap(); if self.memories.contains_key(&key){ let m = self.memories.get(&key).unwrap().clone(); - m.borrow_mut().init(value, self); + m.get_internal_mut().init(value, self); } else{ let m = Memory::from_game_object(value, self); diff --git a/src/structures/character.rs b/src/structures/character.rs index 61f75c5..0ded068 100644 --- a/src/structures/character.rs +++ b/src/structures/character.rs @@ -2,7 +2,7 @@ use minijinja::context; use serde::{Serialize, ser::SerializeStruct}; -use crate::{game_object::{GameObject, GameString, SaveFileValue, Wrapper}, game_state::GameState}; +use crate::{game_object::{GameObject, GameString, SaveFileValue, Wrapper, WrapperMut}, game_state::GameState}; use super::{renderer::Renderable, serialize_array, Cullable, Culture, DerivedRef, Dynasty, Faith, GameId, GameObjectDerived, Memory, Shared, Title}; @@ -118,7 +118,7 @@ fn get_family(self_id:GameId, spouses:&mut Vec>, former_spouse SaveFileValue::Object(o) => { for s in o.get_array_iter(){ let c = game_state.get_character(&s.as_id()).clone(); - let contains = former_spouses.iter().any(|x| x.as_ref().borrow().get_id() == c.as_ref().borrow().get_id()); + let contains = former_spouses.iter().any(|x| x.get_internal().get_id() == c.get_internal().get_id()); if !contains{ spouses.push(c); } @@ -126,7 +126,7 @@ fn get_family(self_id:GameId, spouses:&mut Vec>, former_spouse } SaveFileValue::String(o) => { let c = game_state.get_character(&o.parse::().unwrap()).clone(); - let contains = former_spouses.iter().any(|x| x.as_ref().borrow().get_id() == c.as_ref().borrow().get_id()); + let contains = former_spouses.iter().any(|x| x.get_internal().get_id() == c.get_internal().get_id()); if !contains{ spouses.push(c); } @@ -136,8 +136,8 @@ fn get_family(self_id:GameId, spouses:&mut Vec>, former_spouse let primary_spouse_node = f.get("primary_spouse"); if primary_spouse_node.is_some() { let c = game_state.get_character(&primary_spouse_node.unwrap().as_id()).clone(); - let mut contains = former_spouses.iter().any(|x| x.as_ref().borrow().get_id() == c.as_ref().borrow().get_id()); - contains = contains || spouses.iter().any(|x| x.as_ref().borrow().get_id() == c.as_ref().borrow().get_id()); + let mut contains = former_spouses.iter().any(|x| x.get_internal().get_id() == c.get_internal().get_id()); + contains = contains || spouses.iter().any(|x| x.get_internal().get_id() == c.get_internal().get_id()); if !contains{ spouses.push(c); } @@ -147,7 +147,7 @@ fn get_family(self_id:GameId, spouses:&mut Vec>, former_spouse let parent = game_state.get_character(&self_id); for s in children_node.unwrap().as_object().unwrap().get_array_iter(){ let c = game_state.get_character(&s.as_id()).clone(); - c.borrow_mut().register_parent(parent.clone()); + c.get_internal_mut().register_parent(parent.clone()); children.push(c); } } @@ -233,7 +233,7 @@ fn get_dynasty(base:&GameObject, game_state:&mut GameState) -> Option::from_derived(h.clone()); state.serialize_field("house", &rd)?; if faith.is_none(){ - let o = h.as_ref().borrow(); + let o = h.get_internal(); faith = o.get_faith(); } if culture.is_none(){ - let o = h.as_ref().borrow(); + let o = h.get_internal(); culture = o.get_culture(); } } @@ -507,37 +507,37 @@ impl Renderable for Character { return; } if self.faith.is_some(){ - self.faith.as_ref().unwrap().as_ref().borrow().render_all(renderer); + self.faith.as_ref().unwrap().get_internal().render_all(renderer); } if self.culture.is_some(){ - self.culture.as_ref().unwrap().as_ref().borrow().render_all(renderer); + self.culture.as_ref().unwrap().get_internal().render_all(renderer); } if self.house.is_some(){ - self.house.as_ref().unwrap().as_ref().borrow().render_all(renderer); + self.house.as_ref().unwrap().get_internal().render_all(renderer); } for s in self.spouses.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for s in self.former.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for s in self.children.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for s in self.parents.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for s in self.kills.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for s in self.vassals.iter(){ - s.as_ref().borrow().get_ref().as_ref().borrow().render_all(renderer); + s.get_internal().get_ref().get_internal().render_all(renderer); } for s in self.titles.iter(){ - s.as_ref().borrow().render_all(renderer); + s.get_internal().render_all(renderer); } for m in self.memories.iter() { - m.as_ref().borrow().render_participants(renderer); + m.get_internal().render_participants(renderer); } } } @@ -549,64 +549,64 @@ impl Cullable for Character { } self.depth = depth; for s in self.spouses.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.former.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.children.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.parents.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.kills.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.vassals.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ - o.unwrap().get_ref().as_ref().borrow_mut().set_depth(depth - 1); + o.unwrap().get_ref().get_internal_mut().set_depth(depth - 1); } } if self.culture.is_some(){ - let o = self.culture.as_ref().unwrap().try_borrow_mut(); + let o = self.culture.as_ref().unwrap().try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } if self.faith.is_some(){ - let o = self.faith.as_ref().unwrap().try_borrow_mut(); + let o = self.faith.as_ref().unwrap().try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.titles.iter(){ - let o = s.try_borrow_mut(); + let o = s.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } for s in self.memories.iter(){ - s.borrow_mut().set_depth(depth - 1); + s.get_internal_mut().set_depth(depth - 1); } if self.house.is_some(){ - let o = self.house.as_ref().unwrap().try_borrow_mut(); + let o = self.house.as_ref().unwrap().try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } diff --git a/src/structures/culture.rs b/src/structures/culture.rs index 1c5a95a..25621a5 100644 --- a/src/structures/culture.rs +++ b/src/structures/culture.rs @@ -3,7 +3,7 @@ use serde::Serialize; use serde::ser::SerializeStruct; use super::renderer::Renderable; use super::{serialize_array, Cullable, GameId, GameObjectDerived, Shared}; -use crate::game_object::{GameObject, GameString, Wrapper}; +use crate::game_object::{GameObject, GameString, Wrapper, WrapperMut}; /// A struct representing a culture in the game pub struct Culture { @@ -140,7 +140,7 @@ impl Renderable for Culture { return; } for p in &self.parents{ - p.borrow().render_all(renderer); + p.get_internal().render_all(renderer); } } } @@ -156,7 +156,7 @@ impl Cullable for Culture { } self.depth = depth; for p in &self.parents{ - p.borrow_mut().set_depth(depth-1); + p.get_internal_mut().set_depth(depth-1); } } } diff --git a/src/structures/derived_ref.rs b/src/structures/derived_ref.rs index d8c86fe..76e8716 100644 --- a/src/structures/derived_ref.rs +++ b/src/structures/derived_ref.rs @@ -1,7 +1,7 @@ use serde::Serialize; use serde::ser::SerializeStruct; -use crate::game_object::GameString; +use crate::game_object::{GameString, WrapperMut}; use super::{Cullable, GameId, GameObjectDerived, Shared, Wrapper}; @@ -18,7 +18,7 @@ impl DerivedRef where T:GameObjectDerived + Cullable{ /// Create a new DerivedRef from a [Shared] object. /// This will clone the object and store a reference to it. pub fn from_derived(obj:Shared) -> Self{ - let o = obj.borrow(); + let o = obj.get_internal(); DerivedRef{ id: o.get_id(), name: o.get_name(), @@ -39,8 +39,8 @@ impl DerivedRef where T:GameObjectDerived + Cullable{ /// Initialize the DerivedRef with a [Shared] object. pub fn init(&mut self, obj:Shared){ - self.id = obj.borrow().get_id(); - self.name = obj.borrow().get_name(); + self.id = obj.get_internal().get_id(); + self.name = obj.get_internal().get_name(); self.obj = obj; } @@ -63,7 +63,7 @@ impl Serialize for DerivedRef where T:GameObjectDerived + Cullable{ let mut state = serializer.serialize_struct("DerivedRef", 3)?; state.serialize_field("id", &self.id)?; state.serialize_field("name", &self.name)?; - let shallow = self.obj.borrow().get_depth() == 0; + let shallow = self.obj.get_internal().get_depth() == 0; state.serialize_field("shallow", &shallow)?; state.end() } @@ -71,10 +71,10 @@ impl Serialize for DerivedRef where T:GameObjectDerived + Cullable{ impl Cullable for DerivedRef where T:GameObjectDerived + Cullable{ fn get_depth(&self) -> usize { - self.obj.borrow().get_depth() + self.obj.get_internal().get_depth() } fn set_depth(&mut self, depth:usize) { - self.obj.borrow_mut().set_depth(depth); + self.obj.get_internal_mut().set_depth(depth); } } diff --git a/src/structures/dynasty.rs b/src/structures/dynasty.rs index 27cf834..7a528b9 100644 --- a/src/structures/dynasty.rs +++ b/src/structures/dynasty.rs @@ -4,7 +4,7 @@ use serde::Serialize; use serde::ser::SerializeStruct; use super::renderer::Renderable; use super::{serialize_array, Character, Cullable, Culture, DerivedRef, Faith, GameId, GameObjectDerived, Shared}; -use crate::game_object::{GameObject, GameString, SaveFileValue, Wrapper}; +use crate::game_object::{GameObject, GameString, SaveFileValue, Wrapper, WrapperMut}; use crate::game_state::GameState; use std::collections::HashMap; @@ -26,13 +26,13 @@ impl Dynasty { /// Gets the faith of the dynasty. /// Really this is just the faith of the current house leader. pub fn get_faith(&self) -> Option> { - self.leaders.last().unwrap().borrow().get_faith() + self.leaders.last().unwrap().get_internal().get_faith() } /// Gets the culture of the dynasty. /// Really this is just the culture of the current house leader. pub fn get_culture(&self) -> Option> { - self.leaders.last().unwrap().borrow().get_culture() + self.leaders.last().unwrap().get_internal().get_culture() } pub fn register_house(&mut self){ @@ -42,7 +42,7 @@ impl Dynasty { pub fn register_member(&mut self){ self.members += 1; if self.parent.as_ref().is_some(){ - let mut p = self.parent.as_ref().unwrap().try_borrow_mut(); + let mut p = self.parent.as_ref().unwrap().try_get_internal_mut(); if p.is_ok(){ p.as_mut().unwrap().register_member(); } @@ -123,7 +123,7 @@ fn get_parent(base:&GameObject, game_state:&mut GameState) -> Option None, k => { let p = game_state.get_dynasty(&k.unwrap().as_id()).clone(); - let m = p.try_borrow_mut(); + let m = p.try_get_internal_mut(); if m.is_err(){ return None; } @@ -143,7 +143,7 @@ fn get_name(base:&GameObject, parent:Option>) -> GameString{ return GameString::wrap("".to_owned().into()); } //this may happen for dynasties with a house with the same name - return parent.unwrap().borrow().name.as_ref().unwrap().clone(); + return parent.unwrap().get_internal().name.as_ref().unwrap().clone(); } } n.unwrap().as_string() @@ -265,7 +265,7 @@ impl Renderable for Dynasty { return; } for leader in self.leaders.iter(){ - leader.borrow().render_all(renderer); + leader.get_internal().render_all(renderer); } } } @@ -277,13 +277,13 @@ impl Cullable for Dynasty { } self.depth = depth; for leader in self.leaders.iter(){ - let o = leader.try_borrow_mut(); + let o = leader.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } } if self.parent.as_ref().is_some(){ - let o = self.parent.as_ref().unwrap().try_borrow_mut(); + let o = self.parent.as_ref().unwrap().try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } diff --git a/src/structures/faith.rs b/src/structures/faith.rs index 7c51eda..b2370ea 100644 --- a/src/structures/faith.rs +++ b/src/structures/faith.rs @@ -3,7 +3,7 @@ use serde::Serialize; use serde::ser::SerializeStruct; use super::{Character, Cullable, DerivedRef, GameId, GameObjectDerived, Shared}; use super::renderer::Renderable; -use crate::game_object::{GameObject, GameString, Wrapper}; +use crate::game_object::{GameObject, GameString, Wrapper, WrapperMut}; use crate::game_state::GameState; /// A struct representing a faith in the game @@ -22,7 +22,7 @@ fn get_head(base:&GameObject, game_state:&mut crate::game_state::GameState) -> O let current = base.get("religious_head"); if current.is_some(){ let title = game_state.get_title(¤t.unwrap().as_id()); - return title.borrow().get_holder(); + return title.get_internal().get_holder(); } None } @@ -142,7 +142,7 @@ impl Renderable for Faith { return; } if self.head.is_some(){ - self.head.as_ref().unwrap().borrow().render_all(renderer); + self.head.as_ref().unwrap().get_internal().render_all(renderer); } } } @@ -158,7 +158,7 @@ impl Cullable for Faith { } self.depth = depth; if self.head.is_some(){ - let o = self.head.as_ref().unwrap().try_borrow_mut(); + let o = self.head.as_ref().unwrap().try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth-1); } diff --git a/src/structures/lineage.rs b/src/structures/lineage.rs index de6a827..aadee61 100644 --- a/src/structures/lineage.rs +++ b/src/structures/lineage.rs @@ -157,7 +157,7 @@ impl GameObjectDerived for LineageNode{ } fn get_name(&self) -> GameString { - self.character.as_ref().unwrap().borrow().get_name() + self.character.as_ref().unwrap().get_internal().get_name() } } diff --git a/src/structures/memory.rs b/src/structures/memory.rs index 032f812..19de93b 100644 --- a/src/structures/memory.rs +++ b/src/structures/memory.rs @@ -1,7 +1,7 @@ use serde::Serialize; use serde::ser::SerializeStruct; use super::{Character, Cullable, DerivedRef, GameId, GameObjectDerived, Renderable, Shared}; -use crate::game_object::{GameObject, GameString, Wrapper}; +use crate::game_object::{GameObject, GameString, Wrapper, WrapperMut}; use crate::game_state::GameState; /// A struct representing a memory in the game @@ -86,7 +86,7 @@ impl Cullable for Memory { } self.depth = depth; for part in self.participants.iter_mut(){ - let o = part.1.try_borrow_mut(); + let o = part.1.try_get_internal_mut(); if o.is_ok(){ o.unwrap().set_depth(depth - 1); } @@ -101,7 +101,7 @@ impl Cullable for Memory { impl Memory{ pub fn render_participants(&self, renderer: &mut super::Renderer) { for part in self.participants.iter() { - let o = part.1.as_ref().try_borrow(); + let o = part.1.try_get_internal(); if o.is_ok() { o.unwrap().render_all(renderer); } diff --git a/src/structures/mod.rs b/src/structures/mod.rs index 97a7ea2..6b87043 100644 --- a/src/structures/mod.rs +++ b/src/structures/mod.rs @@ -4,9 +4,9 @@ mod renderer; pub use renderer::{Cullable, Renderer, Renderable}; use std::rc::Rc; -use std::cell::RefCell; +use std::cell::{BorrowMutError, RefCell, RefMut}; -use crate::game_object::GameString; +use crate::game_object::{GameString, RefOrRaw, WrapperMut}; use super::game_object::{GameObject, GameId, Wrapper}; @@ -56,7 +56,7 @@ pub use derived_ref::{DerivedRef, serialize_array}; /// ``` /// let obj:Shared = Shared::wrap("Hello"); /// -/// let value:Ref = obj.borrow(); +/// let value:Ref = obj.get_internal(); /// ``` pub type Shared = Rc>; @@ -64,6 +64,28 @@ impl Wrapper for Shared { fn wrap(t:T) -> Self { Rc::new(RefCell::new(t)) } + + fn get_internal(&self) -> RefOrRaw { + RefOrRaw::Ref(self.borrow()) + } + + fn try_get_internal(&self) -> Result, std::cell::BorrowError> { + let r = self.try_borrow(); + match r { + Ok(r) => Ok(RefOrRaw::Ref(r)), + Err(e) => Err(e) + } + } +} + +impl WrapperMut for Shared { + fn get_internal_mut(&self) -> RefMut { + self.borrow_mut() + } + + fn try_get_internal_mut(&self) -> Result, BorrowMutError> { + self.try_borrow_mut() + } } /// A trait for objects that can be created from a [GameObject]. diff --git a/src/structures/player.rs b/src/structures/player.rs index 32f5f79..a943da7 100644 --- a/src/structures/player.rs +++ b/src/structures/player.rs @@ -2,7 +2,7 @@ use minijinja::context; use serde::Serialize; use serde::ser::SerializeStruct; -use crate::game_object::{GameObject, GameString, Wrapper}; +use crate::game_object::{GameObject, GameString, Wrapper, WrapperMut}; use crate::game_state::GameState; @@ -97,7 +97,7 @@ impl Renderable for Player{ fn render_all(&self, renderer: &mut Renderer){ renderer.render(self); for char in self.lineage.iter(){ - char.get_character().borrow().render_all(renderer); + char.get_character().get_internal().render_all(renderer); } } } @@ -105,7 +105,7 @@ impl Renderable for Player{ impl Cullable for Player{ fn set_depth(&mut self, depth: usize){ for node in self.lineage.iter(){ - node.get_character().borrow_mut().set_depth(depth); + node.get_character().get_internal_mut().set_depth(depth); } } diff --git a/src/structures/title.rs b/src/structures/title.rs index 00f256c..42fef6a 100644 --- a/src/structures/title.rs +++ b/src/structures/title.rs @@ -3,7 +3,7 @@ use minijinja::context; use serde::Serialize; use serde::ser::SerializeStruct; -use crate::game_object::{GameObject, GameString, SaveFileValue, Wrapper}; +use crate::game_object::{GameObject, GameString, SaveFileValue, Wrapper, WrapperMut}; use crate::game_state::GameState; use super::renderer::Renderable; @@ -251,17 +251,17 @@ impl Renderable for Title { return; } if self.de_jure.is_some(){ - self.de_jure.as_ref().unwrap().borrow().render_all(renderer); + self.de_jure.as_ref().unwrap().get_internal().render_all(renderer); } if self.de_facto.is_some(){ - self.de_facto.as_ref().unwrap().borrow().render_all(renderer); + self.de_facto.as_ref().unwrap().get_internal().render_all(renderer); } for v in &self.vassals{ - v.as_ref().borrow().render_all(renderer); + v.get_internal().render_all(renderer); } for o in &self.history{ if o.1.is_some(){ - o.1.as_ref().unwrap().borrow().render_all(renderer); + o.1.as_ref().unwrap().get_internal().render_all(renderer); } } } @@ -274,17 +274,17 @@ impl Cullable for Title { } self.depth = depth; if self.de_jure.is_some(){ - self.de_jure.as_ref().unwrap().borrow_mut().set_depth(depth-1); + self.de_jure.as_ref().unwrap().get_internal_mut().set_depth(depth-1); } if self.de_facto.is_some(){ - self.de_facto.as_ref().unwrap().borrow_mut().set_depth(depth-1); + self.de_facto.as_ref().unwrap().get_internal_mut().set_depth(depth-1); } for v in &self.vassals{ - v.borrow_mut().set_depth(depth-1); + v.get_internal_mut().set_depth(depth-1); } for o in &self.history{ if o.1.is_some(){ - let c = o.1.as_ref().unwrap().try_borrow_mut(); + let c = o.1.as_ref().unwrap().try_get_internal_mut(); if c.is_ok(){ c.unwrap().set_depth(depth-1); }