Skip to content

Commit

Permalink
Fix missing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
maddymakesgames committed Jun 23, 2024
1 parent 748d39a commit d0fba1c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
54 changes: 47 additions & 7 deletions lib/src/maps/elements/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ macro_rules! entities {
}

entities! {
FallingBlock
FallingBlock, ZipMover, FakeWall, Spring, Refill
(
SpikesUp, "spikesUp",
[kind, "type", ResolvableString]
Expand All @@ -234,11 +234,6 @@ entities! {
JumpThru, "jumpThru",
[texture, "texture", ResolvableString]
),
(
ZipMover, "zipMover",
[]
(target)
),
(
Wire, "wire",
[above, "above", bool]
Expand Down Expand Up @@ -315,7 +310,6 @@ unit_entities! {
Player, "player",
GoldenBerry, "goldenBerry",
CrumbleBlock, "crumbleBlock",
Refill, "refill",
Checkpoint, "checkpoint",
WingedGoldenStrawberry, "memorialTextController",
FlutterBird, "flutterbird"
Expand Down Expand Up @@ -389,3 +383,49 @@ impl Entity for Spring {
encoder.optional_attribute("playerCanUse", &self.player_can_use);
}
}

#[derive(Debug)]
pub struct ZipMover {
pub theme: Option<ResolvableString>,
pub to: Node,
}

impl Entity for ZipMover {
const NAME: &'static str = "zipMover";

fn from_raw(parser: MapParser) -> Result<Self, MapElementParsingError>
where Self: Sized {
Ok(Self {
theme: parser.get_optional_attribute("theme"),
to: parser.parse_element()?,
})
}

fn to_raw(&self, encoder: &mut MapEncoder) {
encoder.optional_attribute("theme", &self.theme);
encoder.child(&self.to);
}
}

#[derive(Debug)]
pub struct Refill {
pub two_dash: Option<bool>,
pub one_use: Option<bool>,
}

impl Entity for Refill {
const NAME: &'static str = "refill";

fn from_raw(parser: MapParser) -> Result<Self, MapElementParsingError>
where Self: Sized {
Ok(Self {
two_dash: parser.get_optional_attribute("twoDash"),
one_use: parser.get_optional_attribute("oneUse"),
})
}

fn to_raw(&self, encoder: &mut MapEncoder) {
encoder.optional_attribute("twoDash", &self.two_dash);
encoder.optional_attribute("oneUse", &self.one_use);
}
}
26 changes: 21 additions & 5 deletions lib/src/maps/elements/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct Level {
pub disable_down_transition: Option<bool>,
pub whisper: Option<bool>,
pub delay_alt_music_fade: Option<bool>,
pub enforce_dash_number: Option<Integer>,
pub c: Integer,
pub entities: Entities,
pub solids: Solids,
Expand All @@ -64,6 +65,8 @@ pub struct Level {
pub fg_decals: FGDecals,
pub bg_tiles: BGTiles,
pub bg_decals: BGDecals,
pub bg: Background,
pub objtiles: ObjTiles,
}

impl MapElement for Level {
Expand Down Expand Up @@ -94,6 +97,7 @@ impl MapElement for Level {
disable_down_transition: parser.get_optional_attribute("disableDownTransition"),
whisper: parser.get_optional_attribute("whisper"),
delay_alt_music_fade: parser.get_optional_attribute("delayAltMusicFade"),
enforce_dash_number: parser.get_optional_attribute("enforceDashNumber"),
c: parser.get_attribute("c")?,
entities: parser.parse_element()?,
solids: parser.parse_element()?,
Expand All @@ -102,6 +106,8 @@ impl MapElement for Level {
fg_decals: parser.parse_element()?,
bg_tiles: parser.parse_element()?,
bg_decals: parser.parse_element()?,
bg: parser.parse_element()?,
objtiles: parser.parse_element()?,
})
}

Expand All @@ -124,7 +130,7 @@ impl MapElement for Level {
}
encoder.optional_attribute("ambience", &self.ambience);
if let Some(progress) = &self.ambience_progress {
encoder.attribute("musicProgress", progress.clone());
encoder.attribute("ambienceProgress", progress.clone());
}
encoder.attribute("underwater", self.underwater);
encoder.optional_attribute("space", &self.space);
Expand All @@ -136,16 +142,19 @@ impl MapElement for Level {
if let Some(alt_music_fade) = self.delay_alt_music_fade {
encoder.attribute("delayAltMusicFade", alt_music_fade);
}
encoder.optional_attribute("enforceDashNumber", &self.enforce_dash_number);
encoder.attribute("x", self.x);
encoder.attribute("y", self.y);
encoder.attribute("c", self.c);
encoder.child(&self.entities);
encoder.child(&self.solids);
encoder.child(&self.triggers);
encoder.child(&self.fg_decals);
encoder.child(&self.fg_tiles);
encoder.child(&self.bg_decals);
encoder.child(&self.fg_decals);
encoder.child(&self.solids);
encoder.child(&self.entities);
encoder.child(&self.bg_tiles);
encoder.child(&self.bg_decals);
encoder.child(&self.bg);
encoder.child(&self.objtiles);
}
}

Expand Down Expand Up @@ -182,6 +191,7 @@ pub struct FGTiles {
pub offset_y: Float,
pub tileset: ResolvableString,
pub export_mode: Integer,
pub inner_text: Option<String>,
}

impl MapElement for FGTiles {
Expand All @@ -194,6 +204,7 @@ impl MapElement for FGTiles {
offset_y: parser.get_attribute("offsetY")?,
tileset: parser.get_attribute("tileset")?,
export_mode: parser.get_attribute("exportMode")?,
inner_text: parser.get_optional_attribute("innerText"),
})
}

Expand All @@ -202,6 +213,10 @@ impl MapElement for FGTiles {
encoder.attribute("offsetY", self.offset_y);
encoder.attribute("tileset", self.tileset.clone());
encoder.attribute("exportMode", self.export_mode);
encoder.optional_attribute(
"innerText",
&self.inner_text.as_ref().map(EncodedVar::new_rle_str),
)
}
}

Expand Down Expand Up @@ -376,6 +391,7 @@ impl MapElement for ObjTiles {
encoder.attribute("offsetX", self.offset_x);
encoder.attribute("offsetY", self.offset_y);
encoder.attribute("tileset", self.tileset.clone());
encoder.attribute("exportMode", self.export_mode);
encoder.optional_attribute(
"innerText",
&self.inner_text.as_ref().map(EncodedVar::new_rle_str),
Expand Down
18 changes: 16 additions & 2 deletions lib/src/maps/elements/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,48 +72,62 @@ impl MapElement for Foregrounds {
}

fn to_raw(&self, encoder: &mut MapEncoder) {
encoder.children(&self.parallax_elements);

if self.snow_fg {
encoder.child(&SnowFG);
}
encoder.children(&self.parallax_elements);
}
}

#[derive(Debug, Clone)]
pub struct Parallax {
pub blend_mode: Option<ResolvableString>,
pub texture: ResolvableString,
pub x: Float,
pub y: Float,
pub scroll_x: Float,
pub scroll_y: Float,
pub loopx: bool,
pub loopy: bool,
pub speed_x: Option<Float>,
pub speed_y: Option<Float>,
pub color: Option<ResolvableString>,
pub alpha: Option<Float>,
}

impl MapElement for Parallax {
const NAME: &'static str = "parallax";

fn from_raw(parser: MapParser) -> Result<Self, MapElementParsingError> {
Ok(Self {
blend_mode: parser.get_optional_attribute("blendmode"),
texture: parser.get_attribute("texture")?,
x: parser.get_attribute("x")?,
y: parser.get_attribute("y")?,
scroll_x: parser.get_attribute("scrollx")?,
scroll_y: parser.get_attribute("scrolly")?,
loopx: parser.get_attribute("loopx")?,
loopy: parser.get_attribute("loopy")?,
speed_x: parser.get_optional_attribute("speedx"),
speed_y: parser.get_optional_attribute("speedy"),
color: parser.get_optional_attribute("color"),
alpha: parser.get_optional_attribute("alpha"),
})
}

fn to_raw(&self, encoder: &mut MapEncoder) {
encoder.optional_attribute("blendmode", &self.blend_mode);
encoder.attribute("texture", self.texture.clone());
encoder.attribute("x", self.x);
encoder.attribute("y", self.y);
encoder.attribute("scrollx", self.scroll_x);
encoder.attribute("scrolly", self.scroll_y);
encoder.attribute("loopx", self.loopx);
encoder.attribute("loopy", self.loopy);
encoder.optional_attribute("speedx", &self.speed_x);
encoder.optional_attribute("speedy", &self.speed_y);
encoder.optional_attribute("color", &self.color);
encoder.optional_attribute("alpha", &self.alpha);
}
}

Expand Down

0 comments on commit d0fba1c

Please sign in to comment.