Skip to content

Commit

Permalink
[#41] Pants (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir authored Sep 17, 2023
1 parent 2b0c497 commit bfbbe89
Show file tree
Hide file tree
Showing 62 changed files with 394 additions and 120 deletions.
2 changes: 1 addition & 1 deletion macro_convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "macro_convert"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
5 changes: 2 additions & 3 deletions macro_convert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn handle_enum(name: &Ident, data: &DataEnum) -> TokenStream2 {
let default: Ident = get_default(data);

return quote! {
use std::fmt;

#[automatically_derived]
impl #name {
Expand All @@ -36,8 +35,8 @@ fn handle_enum(name: &Ident, data: &DataEnum) -> TokenStream2 {
}

#[automatically_derived]
impl fmt::Display for #name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl std::fmt::Display for #name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
Expand Down
2 changes: 1 addition & 1 deletion macro_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = "macro_core"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
2 changes: 1 addition & 1 deletion macro_ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "macro_ui"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
20 changes: 10 additions & 10 deletions macro_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ fn handle_enum(name: &Ident, data: &DataEnum) -> TokenStream2 {
if is_simple_enum(data) {
return quote! {
#[automatically_derived]
impl UI for #name {
fn visit(visitor: &mut dyn UiVisitor, spaces: &str, _in_tuple: bool) {
impl macro_core::visitor::UI for #name {
fn visit(visitor: &mut dyn macro_core::visitor::UiVisitor, spaces: &str, _in_tuple: bool) {
println!("{}Add simple enum {} with path '{}'!", spaces, stringify!(#name), visitor.get_path());
visitor.add_simple_enum(&[#(stringify!(#variants).to_string()),*]);
}
}

#[automatically_derived]
impl #name {
pub fn parse<'a>(parser: &'a dyn UiParser<'a>, path: &str, spaces: &str) -> #name {
pub fn parse<'a>(parser: &'a dyn macro_core::parser::UiParser<'a>, path: &str, spaces: &str) -> #name {
println!("{}Parse simple enum {} with path '{}'", spaces, stringify!(#name), path);
get_enum(parser, path)
macro_core::parser::get_enum(parser, path)
}
}
};
Expand All @@ -61,8 +61,8 @@ fn handle_enum(name: &Ident, data: &DataEnum) -> TokenStream2 {

quote! {
#[automatically_derived]
impl UI for #name {
fn visit(visitor: &mut dyn UiVisitor, spaces: &str, _in_tuple: bool) {
impl macro_core::visitor::UI for #name {
fn visit(visitor: &mut dyn macro_core::visitor::UiVisitor, spaces: &str, _in_tuple: bool) {
println!("{}Create Viewer for enum {} with path '{}'!", spaces, stringify!(#name), visitor.get_path());
visitor.enter_enum(&[#(stringify!(#variants).to_string()),*]);
let inner_spaces = format!(" {}", spaces);
Expand All @@ -74,7 +74,7 @@ fn handle_enum(name: &Ident, data: &DataEnum) -> TokenStream2 {

#[automatically_derived]
impl #name {
pub fn parse<'a>(parser: &'a dyn UiParser<'a>, path: &str, spaces: &str) -> #name {
pub fn parse<'a>(parser: &'a dyn macro_core::parser::UiParser<'a>, path: &str, spaces: &str) -> #name {
println!("{}Parse complex enum {} with path '{}'", spaces, stringify!(#name), path);
let t = parser.get_str(&format!("{}.type", path)).unwrap_or("");
println!("{}type '{}'", spaces, t);
Expand All @@ -96,8 +96,8 @@ fn handle_struct(name: &Ident, fields: &FieldsNamed) -> TokenStream2 {

quote! {
#[automatically_derived]
impl UI for #name {
fn visit(visitor: &mut dyn UiVisitor, spaces: &str, in_tuple: bool) {
impl macro_core::visitor::UI for #name {
fn visit(visitor: &mut dyn macro_core::visitor::UiVisitor, spaces: &str, in_tuple: bool) {
println!("{}Create Viewer for struct {} with path '{}' & in_tuple={}!", spaces, stringify!(#name), visitor.get_path(), in_tuple);
visitor.enter_struct(in_tuple);
let inner_spaces = format!(" {}", spaces);
Expand All @@ -109,7 +109,7 @@ fn handle_struct(name: &Ident, fields: &FieldsNamed) -> TokenStream2 {

#[automatically_derived]
impl #name {
pub fn parse<'a>(parser: &'a dyn UiParser<'a>, path: &str, spaces: &str) -> #name {
pub fn parse<'a>(parser: &'a dyn macro_core::parser::UiParser<'a>, path: &str, spaces: &str) -> #name {
println!("{}Parse struct {} with path '{}'", spaces, stringify!(#name), path);
Self {
#parsed_fields
Expand Down
4 changes: 1 addition & 3 deletions macro_ui/tests/parse_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use macro_convert::Convert;
use macro_core::parser::get_enum;
use macro_core::parser::{MockParser, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_core::parser::MockParser;
use macro_ui::ui;
use std::collections::HashMap;

Expand Down
22 changes: 22 additions & 0 deletions resources/characters/characters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
skin:
type: NormalSkin
color: Fair
clothing:
type: Simple
pants:
style: Regular
color: Blue
head:
ears:
type: Normal
Expand Down Expand Up @@ -66,6 +71,8 @@
skin:
type: Scales
color: Red
clothing:
type: None
head:
ears:
type: Normal
Expand Down Expand Up @@ -152,6 +159,11 @@
skin:
type: ExoticSkin
color: White
clothing:
type: Simple
pants:
style: Balloon
color: Red
head:
ears:
type: Normal
Expand Down Expand Up @@ -206,6 +218,11 @@
skin:
type: ExoticSkin
color: Green
clothing:
type: Simple
pants:
style: Regular
color: Purple
head:
ears:
type: None
Expand Down Expand Up @@ -248,6 +265,11 @@
skin:
type: NormalSkin
color: Light
clothing:
type: Simple
pants:
style: Regular
color: Gray
head:
ears:
type: Normal
Expand Down
19 changes: 19 additions & 0 deletions resources/templates/appearance_edit.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@
{% endif %}
</ul>
</li>
<li>
<b>Clothing:</b> {{ macros::add_select(name="appearance.body.clothing.type", options=[ "None","Simple" ], selected=appearance.body.clothing.type, update=true) }}
<ul>
{% if appearance.body.clothing.type == "None" %}
{% elif appearance.body.clothing.type == "Simple" %}
<li>
<b>Pants</b>
<ul>
<li>
<b>Style:</b> {{ macros::add_select(name="appearance.body.clothing.pants.style", options=[ "Balloon","Bermuda","HotPants","Regular","Shorts" ], selected=appearance.body.clothing.pants.style, update=true) }}
</li>
<li>
<b>Color:</b> {{ macros::add_select(name="appearance.body.clothing.pants.color", options=[ "Aqua","Black","Blue","Fuchsia","Gray","Green","Lime","Maroon","Navy","Olive","Orange","Purple","Red","SaddleBrown","Silver","Teal","White","Yellow" ], selected=appearance.body.clothing.pants.color, update=true) }}
</li>
</ul>
</li>
{% endif %}
</ul>
</li>
</ul>
</li>
<li>
Expand Down
19 changes: 19 additions & 0 deletions resources/templates/character.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,25 @@
{% endif %}
</ul>
</li>
<li>
<b>Clothing</b>: {{ appearance.body.clothing.type }}
<ul>
{% if appearance.body.clothing.type == "None" %}
{% elif appearance.body.clothing.type == "Simple" %}
<li>
<b>Pants</b>
<ul>
<li>
<b>Style:</b> {{ appearance.body.clothing.pants.style }}
</li>
<li>
<b>Color:</b> {{ appearance.body.clothing.pants.color }}
</li>
</ul>
</li>
{% endif %}
</ul>
</li>
</ul>
</li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion rpg_tools_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rpg_tools_core"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/beard/full.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/beard/goatee.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/beard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::model::character::appearance::beard::goatee::GoateeStyle;
use crate::model::character::appearance::beard::moustache::MoustacheStyle;
use crate::model::color::Color;
use crate::model::length::Length;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
5 changes: 3 additions & 2 deletions rpg_tools_core/src/model/character/appearance/body.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::model::character::appearance::skin::Skin;
use crate::model::equipment::appearance::Clothing;
use crate::model::width::Width;
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand All @@ -13,6 +12,7 @@ pub struct Body {
/// How wide is the body?
pub width: Width,
pub skin: Skin,
pub clothing: Clothing,
}

impl Default for Body {
Expand All @@ -27,6 +27,7 @@ impl Body {
shape: BodyShape::Rectangle,
width: Width::Average,
skin,
clothing: Clothing::None,
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/ear/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::model::character::appearance::ear::shape::EarShape;
use crate::model::size::Size;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/ear/shape.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/eye/brow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::model::character::appearance::eye::brow::shape::EyebrowShape;
use crate::model::character::appearance::eye::brow::style::EyebrowStyle;
use crate::model::color::Color;
use crate::model::width::Width;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/eye/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::model::character::appearance::eye::pupil::PupilShape;
use crate::model::character::appearance::eye::shape::EyeShape;
use crate::model::color::Color;
use crate::model::size::Size;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/eye/pupil.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/eye/shape.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/hair/bun.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::model::size::Size;
use macro_convert::Convert;
use macro_core::parser::get_enum;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/hair/long.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 0 additions & 2 deletions rpg_tools_core/src/model/character/appearance/hair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::model::character::appearance::hair::short::ShortHair;
use crate::model::color::Color;
use crate::model::length::Length;
use crate::model::size::Size;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::model::character::appearance::hair::ponytail::position::PonytailPosit
use crate::model::character::appearance::hair::ponytail::style::PonytailStyle;
use crate::model::color::Color;
use crate::model::length::Length;
use macro_core::parser::UiParser;
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use macro_convert::Convert;
use macro_core::parser::{get_enum, UiParser};
use macro_core::visitor::{UiVisitor, UI};
use macro_ui::ui;
use serde::{Deserialize, Serialize};

Expand Down
Loading

0 comments on commit bfbbe89

Please sign in to comment.