cleans up
This commit is contained in:
@@ -12,29 +12,28 @@ pub struct Player {
|
||||
pp: i32,
|
||||
}
|
||||
|
||||
/// The sign of the update
|
||||
enum WealthUpdateKind {
|
||||
Income,
|
||||
Expense,
|
||||
}
|
||||
|
||||
/// Representation of wealth value
|
||||
type WealthValues = (i32, i32, i32, i32);
|
||||
|
||||
/// Wealth represented as a single fractionnal amount of gold pieces
|
||||
struct WealthInGold(f32);
|
||||
/// Data used to update wealth
|
||||
struct WealthUpdate {
|
||||
kind: WealthUpdateKind,
|
||||
values: WealthValues,
|
||||
}
|
||||
struct WealthUpdate(WealthInGold);
|
||||
|
||||
impl WealthUpdate {
|
||||
/// Create a new update
|
||||
fn new(values: WealthValues, kind: WealthUpdateKind) -> Self {
|
||||
WealthUpdate { kind, values }
|
||||
impl WealthInGold {
|
||||
/// Unpack individual pieces counts from gold value
|
||||
fn unpack(self) -> (i32, i32, i32, i32) {
|
||||
// TODO: 0,01 pp = 1 gp = 10 sp = 100 cp
|
||||
(0,0,0,0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl WealthUpdate {
|
||||
/// Apply the update to the specified player
|
||||
fn apply_to(self, player_id: i32) {}
|
||||
fn commit(self, player_id: i32) {
|
||||
// Extract (cp, sp, gp, pp) from floating gold piece value
|
||||
// Update record in db
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation of a new player record
|
||||
@@ -49,8 +48,8 @@ pub struct NewPlayer<'a> {
|
||||
}
|
||||
|
||||
impl<'a> NewPlayer<'a> {
|
||||
fn new(name: &'a str, wealth: Option<WealthValues>) -> Self {
|
||||
let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0));
|
||||
fn new(name: &'a str, wealth: Option<WealthInGold>) -> Self {
|
||||
let (cp, sp, gp, pp) = wealth.map(|w| w.unpack()).unwrap_or((0, 0, 0, 0));
|
||||
NewPlayer {
|
||||
name,
|
||||
cp,
|
||||
|
||||
Reference in New Issue
Block a user