1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Load more config data from files (instead of hardcoded)

This commit is contained in:
NGnius (Graham)
2025-03-30 17:54:06 -04:00
parent 0e048a17b1
commit a540cf6d8f
17 changed files with 244 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ use serde::{Serialize, Deserialize};
use polariton::operation::{Typed, Dict};
use polariton::serdes::TypePrefix;
use super::super::{MovementCategoryData, MovementData, Cube, ItemCategory, ItemTier, BattleConfig};
use super::super::{MovementCategoryData, MovementData, Cube, ItemCategory, ItemTier, BattleConfig, Settings};
const CUBE_CONFIG_FILENAME: &str = "config.json";
@@ -15,6 +15,7 @@ pub struct CubeConfig {
movement: HashMap<ItemCategory, MovementCategoryData>,
lerp_value: f32,
battle: BattleConfig,
settings: Settings,
}
impl CubeConfig {
@@ -231,4 +232,19 @@ impl <C: Clone> super::ConfigProvider<C> for CubeConfig {
}
super::CompleteCampaignProvider::new(map)
}
fn client_config(&self) -> Typed<C> {
let conf_data: crate::data::client_config::GameplaySettings = self.settings.gameplay.clone().into();
Typed::Dict(Dict {
key_ty: TypePrefix::Str,
val_ty: TypePrefix::HashMap,
items: vec![
(Typed::Str("GameplaySettings".into()), conf_data.as_transmissible()),
].into(),
})
}
fn login_messages(&self) -> super::DevMessageProvider<C> {
super::DevMessageProvider::new(self.settings.banners.iter().map(|msg| (msg.message.clone(), msg.duration as i32)).collect())
}
}

View File

@@ -2,7 +2,7 @@ mod cubes_json;
pub use cubes_json::CubeConfig;
mod traits;
pub use traits::{ConfigProvider, CompleteCampaignProvider};
pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider};
pub type ConfigImpl = CubeConfig;

View File

@@ -1,6 +1,6 @@
use polariton::operation::Typed;
pub trait ConfigProvider<C> {
pub trait ConfigProvider<C: Clone> {
fn cube_list(&self) -> Typed<C>;
fn movement_list(&self) -> Typed<C>;
fn weapon_list(&self) -> Typed<C>;
@@ -15,6 +15,8 @@ pub trait ConfigProvider<C> {
fn campaign_waves(&self) -> Typed<C>;
fn campaign_version(&self) -> Typed<C>;
fn campaign_details(&self) -> CompleteCampaignProvider;
fn client_config(&self) -> Typed<C>;
fn login_messages(&self) -> DevMessageProvider<C>;
}
pub struct CompleteCampaignProvider {
@@ -40,3 +42,43 @@ impl CompleteCampaignProvider {
}
}
}
pub struct DevMessageProvider<C: Clone> {
messages: Vec<TypedDevMessage<C>>,
}
impl <C: Clone> DevMessageProvider<C> {
pub fn new(messages: Vec<(String, i32)>) -> Self {
Self {
messages: messages.into_iter().map(|(msg, time)| {
let bytes: Vec<u8> = msg.as_bytes().into();
TypedDevMessage {
message: Typed::Bytes(bytes.into()),
display_time: Typed::Int(time),
}
}
).collect(),
}
}
pub fn get(&self, index: usize) -> TypedDevMessage<C> {
// TODO maybe make this less obtuse -- it works for random, but isn't really obvious for anything else
if self.messages.is_empty() {
TypedDevMessage {
message: Typed::Bytes(Vec::default().into()),
display_time: Typed::Int(-1),
}
} else if self.messages.len() == 1 {
self.messages[0].clone()
} else {
let actual_index = index % self.messages.len(); // guarantees index is within allowed range of messages
self.messages[actual_index].clone()
}
}
}
#[derive(Clone, Debug)]
pub struct TypedDevMessage<C> {
pub message: Typed<C>,
pub display_time: Typed<C>,
}