From 0288d0956330d5ac8db48b752240f723e8703929 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 12 Sep 2025 04:02:02 +0800 Subject: feat: initial basic roll features --- src/types.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/types.rs (limited to 'src/types.rs') diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..a88cbab --- /dev/null +++ b/src/types.rs @@ -0,0 +1,65 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DiceResult { + pub expression: String, + pub total: i32, + pub rolls: Vec>, + pub details: String, + pub comment: Option, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct DiceRoll { + pub count: i32, + pub sides: i32, + pub modifiers: Vec, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum DiceModifier { + Explode, // ! + Reroll(i32), // rX + RerollOnce(i32), // roX + KeepHigh(i32), // khX + KeepLow(i32), // klX + DropHigh(i32), // dhX + DropLow(i32), // dlX +} + + +#[derive(Debug, Clone)] +pub enum Expression { + Number(i32), + DiceRoll(DiceRoll), + Add(Box, Box), + Subtract(Box, Box), + Multiply(Box, Box), + Divide(Box, Box), + Power(Box, Box), + Paren(Box), + WithComment(Box, Option), +} + +// TODO: Variable storage +#[derive(Debug, Clone, Default)] +pub struct VariableStore { + pub variables: HashMap, +} + +impl VariableStore { + pub fn new() -> Self { + Self { + variables: HashMap::new(), + } + } + + pub fn set(&mut self, name: &str, value: i32) { + self.variables.insert(name.to_string(), value); + } + + pub fn get(&self, name: &str) -> Option { + self.variables.get(name).copied() + } +} -- cgit v1.2.3-70-g09d2