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

@@ -1,32 +0,0 @@
use polariton::operation::Typed;
pub struct GameplaySettings {
pub show_tutorial_after_date: String,
pub health_threshold: f32, // percent
pub microbot_sphere: f32, // radius
pub misfire_angle: f32, // degrees?
pub shield_dps: i32,
pub shield_hps: u32,
pub request_review_level: u32,
pub critical_ratio: f32,
pub cross_promo_image: String, // url
pub cross_promo_link: String, // url
}
impl GameplaySettings {
pub fn as_transmissible(&self) -> Typed {
Typed::HashMap(vec![
// TODO
(Typed::Str("showTutorialAfterDate".into()), Typed::Str(self.show_tutorial_after_date.clone().into())),
(Typed::Str("healthTresholdPercent".into()), Typed::Float(self.health_threshold)),
(Typed::Str("microbotSphereRadius".into()), Typed::Float(self.microbot_sphere)),
(Typed::Str("smartRotationMisfireAngle".into()), Typed::Float(self.misfire_angle)),
(Typed::Str("fusionShieldDPS".into()), Typed::Int(self.shield_dps)),
(Typed::Str("fusionShieldHPS".into()), Typed::Int(self.shield_hps as i32)),
(Typed::Str("requestReviewAtLevel".into()), Typed::Int(self.request_review_level as i32)),
(Typed::Str("criticalRatio".into()), Typed::Float(self.critical_ratio)),
(Typed::Str("crossPromotionAdImageUrl".into()), Typed::Str(self.cross_promo_image.clone().into())),
(Typed::Str("crossPromotionAdLinkUrl".into()), Typed::Str(self.cross_promo_link.clone().into())),
].into())
}
}

View File

@@ -2,7 +2,7 @@ pub use rc_core::data::cube_list;
pub mod special_item;
pub mod premium_config;
pub mod palette;
pub mod client_config;
//pub mod client_config;
pub mod crf_config;
pub use rc_core::data::weapon_list;
//pub use rc_core::data::movement_list;

View File

@@ -1,31 +1,14 @@
use polariton_server::operations::SimpleFunc;
use polariton::{operation::{Dict, ParameterTable, Typed}, serdes::TypePrefix};
use crate::data::client_config::*;
use polariton_server::operations::Immediate;
//use polariton::{operation::{Dict, ParameterTable, Typed}, serdes::TypePrefix};
use rc_core::ConfigProvider;
const PARAM_KEY: u8 = 36;
pub(super) fn client_config_provider() -> SimpleFunc<34, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Dict(Dict {
key_ty: TypePrefix::Str, // str
val_ty: TypePrefix::HashMap, // hashtable
items: vec![
(Typed::Str("GameplaySettings".into()), GameplaySettings {
show_tutorial_after_date: "2030-01-01".to_owned(),
health_threshold: 0.20,
microbot_sphere: 10.0,
misfire_angle: 10.0,
shield_dps: 100,
shield_hps: 2_000,
request_review_level: 10_000,
critical_ratio: 5.0,
cross_promo_image: "https://git.ngram.ca/assets/img/logo.png".to_owned(),
cross_promo_link: "https://git.ngram.ca/OpenJam/servers".to_owned(),
}.as_transmissible())
].into(),
}));
Ok(params.into())
pub(super) fn client_config_provider(conf: &rc_core::ConfigImpl) -> Immediate<34, crate::UserTy> {
let client_conf = conf.client_config();
Immediate::new(|| {
let mut params = std::collections::HashMap::with_capacity(1);
params.insert(PARAM_KEY, client_conf.clone());
params.into()
})
}

View File

@@ -1,14 +1,19 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed};
use polariton::operation::ParameterTable;
use rand::Rng;
use rc_core::ConfigProvider;
const MESSAGE_PARAM_KEY: u8 = 2;
const DISPLAY_TIME_PARAM_KEY: u8 = 15;
pub(super) fn dev_message_provider() -> SimpleFunc<8, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
pub(super) fn dev_message_provider(conf: &rc_core::ConfigImpl) -> SimpleFunc<8, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
let messages = conf.login_messages();
SimpleFunc::new(move |params, _| {
let mut params = params.to_dict();
params.insert(MESSAGE_PARAM_KEY, Typed::Bytes(Vec::from("No jam was harmed in the reverse-engineering of this game".as_bytes()).into()));
params.insert(DISPLAY_TIME_PARAM_KEY, Typed::Int(60 /* seconds??? */));
let index = rand::rng().random::<u32>();
let dev_msg = messages.get(index as _);
params.insert(MESSAGE_PARAM_KEY, dev_msg.message);
params.insert(DISPLAY_TIME_PARAM_KEY, dev_msg.display_time);
Ok(params.into())
})
}

View File

@@ -22,8 +22,8 @@ impl <C> Operation<C> for UserFlagsTeller {
let mut resp_params = std::collections::HashMap::new();
resp_params.insert(Self::REMOVE_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false.into()));
resp_params.insert(Self::REMOVE_UNOWNED_CUBES_KEY, polariton::operation::Typed::Bool(false.into()));
resp_params.insert(Self::REWARD_TITLE_KEY, polariton::operation::Typed::Str("Yay a reward!".into()));
resp_params.insert(Self::REWARD_BODY_KEY, polariton::operation::Typed::Str("I love you very much so here's nothing as a reward.".into()));
resp_params.insert(Self::REWARD_TITLE_KEY, polariton::operation::Typed::Str("".into()));
resp_params.insert(Self::REWARD_BODY_KEY, polariton::operation::Typed::Str("".into())); // set this to non-empty to display pop-up at login
resp_params.insert(Self::REFUND_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false.into()));
resp_params.insert(Self::CUBES_ARE_REPLACED_KEY, polariton::operation::Typed::Bool(false.into()));
resp_params.insert(Self::NEW_USER_KEY, polariton::operation::Typed::Bool(false.into()));

View File

@@ -100,7 +100,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.without_state(special_items::special_item_list_provider())
.without_state(premium_config::premium_config_provider())
.without_state(palette_town::kanto())
.without_state(client_config::client_config_provider())
.without_state(client_config::client_config_provider(&init_ctx.cubes))
.without_state(crf_config::crf_config_provider())
.without_state(weapon_stats::weapon_config_provider(&init_ctx.cubes))
.without_state(movement_stats::movement_config_provider(&init_ctx.cubes))
@@ -122,7 +122,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.without_state(robopass_season::robopass_season_provider())
.without_state(owned_cosmetics::owned_cosmetics_provider())
.without_state(owned_cosmetics::selected_cosmetics_provider())
.without_state(dev_message::dev_message_provider())
.without_state(dev_message::dev_message_provider(&init_ctx.cubes))
.without_state(custom_games_maps::allowed_maps_provider())
.without_state(avatar_info::get_avatar_provider())
.without_state(custom_game_session::get_custom_session_provider())