Refactor item purchase logic into core, implement promo codes #70

This commit is contained in:
NG (Graham) committed 2026-01-03 11:19:24 -05:00
1 parent 2c6ef3edbe
commit 2f826835dc
10 files changed
+298 -68

No files matched your search

+20
View File
@@ -508,4 +508,24 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
fn shop_entries(&self) -> super::ShopEntriesResolver {
super::ShopEntriesResolver::new(self.shop.items.clone())
}
fn promo_codes(&self) -> std::collections::HashMap<String, super::PromoCode> {
let mut map = std::collections::HashMap::with_capacity(self.shop.promo_codes.len());
for (key, val) in self.shop.promo_codes.iter() {
let tx = super::ShopAction {
cost_free: 0,
cost_paid: 0,
gives: val.gives.iter().map(|x| x.to_owned().into()).collect(),
};
map.insert(key.to_owned(), super::PromoCode {
message: val.message.clone(),
bundle_id: val.bundle_id.to_owned().unwrap_or_else(|| key.to_owned()),
promo_id: val.promo_id.to_owned().unwrap_or_else(|| key.to_owned()),
is_serial: val.is_serial,
value: val.value,
transaction: tx,
});
}
map
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ mod cubes_json;
pub use cubes_json::CubeConfig;
mod traits;
pub use traits::{ConfigProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig, BattleArenaResolver, PitSettings, PitWinCondition, TeamDeathMatchSettings, ShopEntriesResolver, ShopAction, ShopGain};
pub use traits::{ConfigProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig, BattleArenaResolver, PitSettings, PitWinCondition, TeamDeathMatchSettings, ShopEntriesResolver, ShopAction, ShopGain, PromoCode};
mod validation;
pub use validation::{SelfValidator, ValidationInfo, ValidationMessage};
+11
View File
@@ -37,6 +37,7 @@ pub trait ConfigProvider<C: Clone> {
fn pit_settings(&self) -> PitSettings;
fn tdm_settings(&self) -> TeamDeathMatchSettings;
fn shop_entries(&self) -> ShopEntriesResolver;
fn promo_codes(&self) -> std::collections::HashMap<String, PromoCode>;
}
pub struct DevMessageProvider<C: Clone> {
@@ -486,3 +487,13 @@ pub enum ShopGain {
PaidCurrency(i64),
TechPoints(i32)
}
#[derive(Debug)]
pub struct PromoCode {
pub message: Option<String>,
pub bundle_id: String,
pub promo_id: String,
pub is_serial: bool,
pub value: f32,
pub transaction: ShopAction,
}