commit 3bea80f6b5b2d7601539a6d194ca75c937045680 Author: Dandaedre Date: Sun Mar 24 21:32:50 2024 +0100 Fist Commit diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..4bdf9a0 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["-Clink-arg=-fuse-ld=mold", "-Zthreads=24", "-Ctarget-cpu=native"] diff --git a/.config.toml b/.config.toml new file mode 100644 index 0000000..e4bfca5 --- /dev/null +++ b/.config.toml @@ -0,0 +1,3 @@ +[build] +rustflags = ["-Z", "threads=8"] + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c4ba5d1 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,146 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rust20_d10" +version = "0.1.0" +dependencies = [ + "serde", + "toml", +] + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2327a13 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,20 @@ +cargo-features = ["codegen-backend"] +[package] +name = "rust20_d10" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.197", features = ["derive"] } +toml = "0.8.12" + +[profile.dev] +debug = 0 +codegen-backend = "cranelift" + +[profile.release] +lto = true +codegen-units = 1 +panic = "abort" diff --git a/README.md b/README.md new file mode 100644 index 0000000..d14b5af --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# rust20_d10 + +rust20_d10 is a character sheet generator for tabletop role-playing games (TTRPGs) for the roll20 website. +This project is written in Rust, aiming for efficiency, reliability, and speed. + +# Usage + +rust20_d10 diff --git a/data/cyberpunk.toml b/data/cyberpunk.toml new file mode 100644 index 0000000..33c75e0 --- /dev/null +++ b/data/cyberpunk.toml @@ -0,0 +1,682 @@ +[config] + +[data] +head = """ + + +""" +script = "" # The rest is kept for legacy reasons +# """" +# +# """ +header = """ +
+
+
+ +
+ +
+
+
+

Des Utilisé :

+ +
+
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracValeurBonusLancer
Force
Agilité
Perception
Charisme
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CaracValeurBonusLancer
Intelligence
Volonté
Accreditation
Chance
+
+
+
+
+ armor +
+
+
+
+
+
+
+
+
+
+ armor +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+""" + +footer = """ +
+ + + + + + {{#rollWasCrit() result}} + + {{/rollWasCrit() result}} + {{#^rollWasCrit() result}} + {{#rollWasFumble() result}} + {{#rollGreater() result 1}} + + {{/rollGreater() result 1}} + {{#rollBetween() result 0 1}} + + {{/rollBetween() result 0 1}} + {{#rollLess() result 0}} + + {{/rollLess() result 0}} + {{/rollWasFumble() result}} + {{#^rollWasFumble() result}} + {{#rollGreater() result 1}} + + {{/rollGreater() result 1}} + {{#rollBetween() result 0 1}} + + {{/rollBetween() result 0 1}} + {{#rollLess() result 0}} + + {{/rollLess() result 0}} + {{/^rollWasFumble() result}} + {{/^rollWasCrit() result}} + +
{{name}} — {{roll_name}}
Test au d{{dice_name}} seuil {{threshold}}
Critique ! {{result}}x2 degrés de réussiteÉchec critique ! {{result}}/2 degrés de réussiteÉchec critique ! {{result}}/2 degré de réussiteÉchec critique ! {{result}}x2 degrés d'échec{{result}} degrés de réussite{{result}} degré de réussite{{result}} degrés d'échec
+
+ + + + +
{{name}} — {{roll_name}}
1d10+{{value}} = {{result}} + {{#rollWasCrit() result}} + +{{base}} + {{/rollWasCrit() result}} + {{#rollWasFumble() result}} + {{result}}-{{base}} + {{/rollWasFumble() result}} +
+
+ +
+

{{name}}

+
{{subtags}}
+
+ {{#attack}} +
Attack: {{attack}} successes
+ {{#mode}} +
Mode: {{mode}} ({{usedammo}})
+ {{/mode}} + {{/attack}} + {{#damage}} +
+ Damage: {{damage}} +
+ {{#ammocurrent}} +
+ Ammunition: {{ammocurrent}}/{{magsize}} | {{ammototal}} +
+ {{/ammocurrent}} + {{/damage}} + {{#damagedone}} +
+ Damage: {{damagedone}} +
+ {{#ammocurrent}} +
+ Ammunition: {{ammocurrent}}/{{magsize}} | {{ammototal}} +
+ {{/ammocurrent}} + {{/damagedone}} + {{#special}} +
+ Special: {{special}} +
+ {{/special}} +
+
+""" +css_footer = """ +.sheet-header-content { + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: 1fr; + gap: 0px 0px; + grid-auto-flow: row; + grid-template-areas: + "sheet-centered-l sheet-centered-r"; +} + +.sheet-centered-l { grid-area: sheet-centered-l; } +.sheet-centered-r { grid-area: sheet-centered-r; } + +div.sheet-main_tab-content { display: none; } +input.sheet-main_tab1:checked ~ div.sheet-main_tab1, +input.sheet-main_tab2:checked ~ div.sheet-main_tab2, +input.sheet-main_tab3:checked ~ div.sheet-main_tab3, +{ + display: block; +} + +.sheet-imagecontainer{ + display: inline-block; + position: relative; +} + +.sheet-head_hp { + position: absolute; + top: 7px; + left: 50px; +} +.sheet-body_hp { + position: absolute; + top: 59px; + left: 49px; +} +.sheet-left_arm_hp { + position: absolute; + top: 104px; + left: 11px; +} +.sheet-right_arm_hp { + position: absolute; + top: 104px; + left: 88px; +} +.sheet-left_leg_hp { + position: absolute; + top: 208px; + left: 18px; +} +.sheet-right_leg_hp { + position: absolute; + top: 208px; + left: 83px; +} + + +input.sheet-tab{ + -moz-appearance: none; + width:150px; + height: 20px; + top: 5px; + left: 6px; + margin: 5px; + cursor: pointer; + z-index: 1; + content: attr(title); +} +input.sheet-tab::before{ + -moz-appearance: none; + content: attr(title); + border-radius:.5em; + border:2px solid black; + text-align: center; + display: inline-block; + background: black; + color:white; + width: 150px; + height: 20px; + font-size: 18px; +} +input.sheet-tab:checked::before{ + -moz-appearance: none; + background:#CCCCCC; + color:black; + border-radius:.5em; + border:2px solid black; +} + +input.sheet-small_tab{ + -moz-appearance: none; + width:120px; + height: 20px; + cursor: pointer; + z-index: 1; + margin:5px; +} +input.sheet-small_tab::before{ + -moz-appearance: none; + content: attr(title); + border-radius:.5em; + text-align: center; + display: inline-block; + color:white; + background:black; + border:2px solid black; + width: 120px; + height:20px; + font-size: 14px; +} +input.sheet-small_tab:checked::before{ + -moz-appearance: none; + border:2px solid black; + background:#CCCCCC; + color:black; + border-radius:.5em; +} + +input.sheet-skill_name{ + -moz-appearance: textfield; + width:400px; +} + +input.sheet-skill_level{ + -moz-appearance: textfield; + width:2.5em; !important; +} + +input.sheet-skill_hidden{ + visibility: hidden; +} +div.sheet-tab-content{ + border-top-color: #000; + margin: 2px 0 0 0; +} +select.sheet-skill_select{ + width:55px; + margin-bottom:-1px; +} +select.sheet-dice_select{ + width:85px; + margin-bottom:-1px; +} +.sheet-trait{ + width: 25px !important; +-moz-appearance: textfield; +} +.sheet-body_values{ + width: 25px !important; +-moz-appearance: textfield; +} +.sheet-numberbox { + width: 50px; +} + +.sheet-rolltemplate-d10init table, +.sheet-rolltemplate-d10skillcheck table { + border-radius: 6px; + width:100%; + padding:0px; + margin:0px; + padding: 2px; + border: 1px solid; + background-color: #ffffff; + border-width: 1px; + border-style: solid; + border-color: #000; + border-image-source: none; +} +.sheet-rolltemplate-d10init .sheet-roll-title, +.sheet-rolltemplate-d10init th, +.sheet-rolltemplate-d10skillcheck .sheet-roll-title, +.sheet-rolltemplate-d10skillcheck th { + color: rgb(42, 42, 42); + padding:0px; + margin:0px; + padding-left: 5px; + font-size: 1.2em; + text-align: left; + font-family: "Times New Roman", Times, serif; + font-variant: small-caps; + text-transform: capitalize; + border-width: 0px; +} +.sheet-rolltemplate-d10init .sheet-roll-attr, +.sheet-rolltemplate-d10skillcheck .sheet-roll-attr{ + color: #555555; + font-size: 1em; + font-style: italic; + padding:0px; + margin:0px; + padding-left: 9px; + border-width: 0px; + margin-top: -10px; +} +.sheet-rolltemplate-d10init .sheet-roll-success, +.sheet-rolltemplate-d10skillcheck .sheet-roll-success , +.sheet-rolltemplate-d10skillcheck .sheet-roll-fail { + padding:0px; + margin:0px; + border-width: 0px; + padding-left: 5px; +} +.sheet-rolltemplate-d10skillcheck .sheet-roll-crit { + padding:0px; + margin:0px; + border-width: 0px; + padding-left: 5px; + background-color:#b0d6ad; +} +.sheet-rolltemplate-d10skillcheck .sheet-roll-fumble { + padding-left: 5px; + border-width: 0px; + background-color:#d6adad; +} +.sheet-rolltemplate-d10init .sheet-inline, +.sheet-rolltemplate-d10init .inlinerollresult, +.sheet-rolltemplate-d10skillcheck .sheet-inline, +.sheet-rolltemplate-d10skillcheck .inlinerollresult { + background-color: transparent; + border: none; + font-weight: bold; + padding:0px; + font-family: "Times New Roman", Times, serif; +} +.sheet-rolltemplate-d10skillcheck .sheet-inline.sheet-fullcrit, +.sheet-rolltemplate-d10skillcheck .inlinerollresult.fullcrit { + color: #3FB315; + border: none; +} +.sheet-rolltemplate-d10skillcheck .sheet-inline.sheet-fullfail, +.sheet-rolltemplate-d10skillcheck .inlinerollresult.fullfail { + color: #B31515; + border: none; +} +.sheet-rolltemplate-d10skillcheck .inlinerollresult.importantroll { + color: #4A57ED; + border: none; +} + +.sheet-rolltemplate-d10fight-blob{ + border-radius: 6px; + border: 1px solid #898989; + z-index: 1; +} +.sheet-rolltemplate-d10fight table{ + padding:0px; + margin:0px; + text-align: left; + width:100%; + border:none; + cellpadding:3px; + cellspacing:0px; +} +.sheet-rolltemplate-d10fight .sheet-sum{ + padding:0px; + margin:0px; + border:none; + text-align: right; + padding-right:10px; +} +.sheet-rolltemplate-d10fight .sheet-success, +.sheet-rolltemplate-d10fight .sheet-line{ + padding:0px; + margin:0px; + padding-left: 3px; + border:none; +} +.sheet-rolltemplate-d10fight .sheet-critical{ + padding:0px; + margin:0px; + border:none; + padding-left: 3px; + border-radius: 4px; + background-color:#b0d6ad; +} +.sheet-rolltemplate-d10fight .sheet-hit{ + padding:0px; + margin:0px; + padding-left: 3px; + border-radius: 4px; + background-color:#b0d6ad; + border:none; +} +.sheet-rolltemplate-d10fight .sheet-miss{ + padding:0px; + margin:0px; + padding-left: 3px; + border:none; + border-radius: 4px; + background-color:#d6adad; +} +.sheet-rolltemplate-d10fight .sheet-name{ + padding:0px; + padding-left: 3px; + margin:0px; + border:none; + border-radius: 4px; + border-bottom-left-radius: 2px; + border-bottom-right-radius: 2px; + background-color: #999999; +} +.sheet-rolltemplate-d10fight .sheet-additional{ + padding:0px; + margin:0px; + border:none; + padding-left:10px; +} +.sheet-rolltemplate-d10fight-grey{ + color: #999999; +} +.sheet-rolltemplate-d10fight-green{ + color: #009900; +} +.sheet-rolltemplate-d10fight a, +.sheet-rolltemplate-d10fight a[href^="!"], +.sheet-rolltemplate-d10fight a[href^="~"]{ + text-align:right; + background-color: #999999; !important +} + +.sheet-rolltemplate-d10Shooting .sheet-container { + background-color: #ffffff; + border: 1px solid; + padding: 2px; + width: 189px; +} + +.sheet-rolltemplate-d10Shooting .sheet-container h1 { + color: rgb(126, 45, 64); + font-size: 1.2em; + font-variant: small-caps; + line-height: 20px; +} + +.sheet-rolltemplate-d10Shooting div { + padding: 2px; +}; + +.sheet-rolltemplate-d10Shooting span { + color: rgb(126, 45, 64); + font-family: "Times New Roman", Times, serif; + font-size: 1.2em; + font-variant: small-caps; + line-height: 1.6em; + padding-left: 5px; + text-align: left; +} + +.sheet-rolltemplate-d10Shooting .sheet-subheader { + color: #000; + font-size: 1em; + font-style: italic; +} + +.sheet-rolltemplate-d10Shooting .sheet-arrow-right { + border-bottom: 2px solid transparent; + border-left: 180px solid rgb(126, 45, 64); + border-top: 2px solid transparent; +} + +.sheet-rolltemplate-d10Shooting .sheet-tcat { + font-style: italic; +} + +.sheet-rolltemplate-d10Shooting .inlinerollresult { + background-color: #ffffff; + border: none; +} + +.sheet-rolltemplate-d10Shooting .inlinerollresult.fullcrit { + color: #3FB315; + border: none; +} + +.sheet-rolltemplate-d10Shooting .inlinerollresult.fullfail { + color: #B31515; + border: none; +} + +.sheet-rolltemplate-d10Shooting .inlinerollresult.importandivoll { + color: #4A57ED; + border: none; +} + +select.sheet-weapon_type_select{ + line-height: 0px; + margin-bottom:0px; + margin: 0px; +} +label { + display: inline; + margin: 0px; + padding: 0px; +} +div.sheet-row{ + margin: 0px; + padding: 3px; +} +div.sheet-quickborder{ + border: 1px solid #ccc; + border-color: grey; + margin:5px; + padding:5px; +} +div.repeating_ranged-weapon{ + margin:5px; +} +""" diff --git a/src/data_structure.rs b/src/data_structure.rs new file mode 100644 index 0000000..23bfe1c --- /dev/null +++ b/src/data_structure.rs @@ -0,0 +1,21 @@ +//! # Data Structure Module +//! +//! The `data_structure` module provides data structures for representing the loaded sections of a character or a model. + +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct GlobalConfig { + config: Config, + data: Data, +} + +#[derive(Deserialize)] +struct Data { + head: String, + script: String, + header: String, + css_footer: String, +} +#[derive(Deserialize)] +struct Config {} diff --git a/src/export.rs b/src/export.rs new file mode 100644 index 0000000..c2055e0 --- /dev/null +++ b/src/export.rs @@ -0,0 +1,3 @@ +//! # Export Module +//! +//! The `export` module provides functionality to export a character sheet into an HTML template. diff --git a/src/generator.rs b/src/generator.rs new file mode 100644 index 0000000..2bf3ff6 --- /dev/null +++ b/src/generator.rs @@ -0,0 +1,3 @@ +//! # Generator Module +//! +//! The `generator` module provides functionality for generating the final HTML from the loaded data and model. diff --git a/src/loader.rs b/src/loader.rs new file mode 100644 index 0000000..ec1c085 --- /dev/null +++ b/src/loader.rs @@ -0,0 +1,89 @@ +//! # Loader Module +//! +//! The `loader` module provides functionality for loading a specific model file and handling IO operations and errors. + +use std::{borrow::Borrow, fs, io, path::Path}; + +use crate::data_structure::GlobalConfig; + +/// Represents an error during Loading +#[derive(Debug)] +pub enum LoadError { + /// Indicate an IOError occured + Io(io::Error), + /// Indicate the file format is invalid + InvalidFormat, +} + +/// Represents a model once loaded +pub struct SheetModel { + config: Option, +} + +impl SheetModel { + /// Create a new SheetModel + pub fn new() -> SheetModel { + SheetModel { config: None } + } + + /// Loads a model file from the specified path. + /// + /// # Arguments + /// + /// * `path` - A reference to the path of the model file to load. + /// + /// # Returns + /// + /// A Result asserting if the loading was sucessful or a LoadError if an error occurs. + /// + /// # Examples + /// + /// ``` + /// use rust20_d10::loader::ModelLoader; + /// + /// let loader = ModelLoader::new(); + /// match loader.load_model("path/to/model_file.txt") { + /// Ok(model_data) => println!("Model loaded successfully: {:?}", model_data), + /// Err(error) => eprintln!("Error loading model: {:?}", error), + /// } + /// ``` + pub fn load_model

(&mut self, path: P) -> Result<(), LoadError> + where + P: AsRef, + { + // Attempt to read the file + let file_content = fs::read_to_string(&path).map_err(LoadError::Io)?; + + let model_data: GlobalConfig = toml::from_str(&file_content).unwrap(); //. .ok_or(LoadError::InvalidFormat); + + self.config = Some(model_data); + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use std::path::Path; + + use crate::loader::SheetModel; + + #[test] + fn test_creation() { + let modl = SheetModel::new(); + assert!(modl.config.is_none()) + } + + #[test] + fn test_load() { + let mut modl = SheetModel::new(); + assert!(modl.load_model(Path::new("data/cyberpunk.toml")).is_ok()); + assert!(modl.config.is_some()) + } + + #[test] + fn test_bad_load() { + let mut modl = SheetModel::new(); + assert!(modl.load_model(Path::new("wrong_file")).is_err()) + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..fe93736 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,8 @@ +mod data_structure; +mod export; +mod generator; +mod loader; + +fn main() { + println!("Hello, world!"); +}