Skip to content

Commit 475bd14

Browse files
committed
[#122] fix(ModelScript): make curly braces around ani events optional
1 parent 03ca41e commit 475bd14

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/ModelScriptDsl.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@ namespace zenkit {
401401
} else if (iequals(kw, "*eventCamTremor")) {
402402
ani.tremors.push_back(this->parse_eventCamTremor());
403403
} else {
404-
auto const loc = _m_stream.format_location();
405-
ZKLOGW("ModelScript", "Syntax error (%s): invalid keyword in `aniEnum` block: %s", loc.c_str(), kw.c_str());
406-
this->_m_stream.next_line();
404+
// Note: Due to #122 we need to also not crash when there is no terminating curly brace.
405+
// To do this, we simply exit when we don't know the event.
406+
_m_stream.backtrack();
407+
break;
407408
}
408409
}
409410
}
@@ -506,9 +507,9 @@ namespace zenkit {
506507
ani.collision_volume_scale = this->maybe_named("CVS").value_or(1);
507508

508509
// Optional events block.
509-
if (this->maybe<MdsToken::LBRACE>()) {
510-
this->parse_events(ani);
511-
}
510+
// Note: Due to #122 the curly parens are actually optional
511+
this->maybe<MdsToken::LBRACE>();
512+
this->parse_events(ani);
512513

513514
return ani;
514515
}

tests/TestModelScript.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_SUITE("ModelScript") {
2222
CHECK_EQ(script.meshes[4], "AnotherTestModelMesh5.asc");
2323
CHECK_EQ(script.meshes[5], "AnotherTestModelMesh(6).asc");
2424

25-
CHECK_EQ(script.animations.size(), 2);
25+
CHECK_EQ(script.animations.size(), 3);
2626
CHECK_EQ(script.animations[0].name, "aniName1");
2727
CHECK_EQ(script.animations[0].layer, 111);
2828
CHECK_EQ(script.animations[0].next, "aniNext1");
@@ -122,6 +122,32 @@ TEST_SUITE("ModelScript") {
122122
CHECK_EQ(script.animations[1].tremors[0].field3, 883);
123123
CHECK_EQ(script.animations[1].tremors[0].field4, 884);
124124

125+
CHECK_EQ(script.animations[2].name, "aniName3");
126+
CHECK_EQ(script.animations[2].layer, 113);
127+
CHECK_EQ(script.animations[2].next, "aniNext3");
128+
CHECK_EQ(script.animations[2].blend_in, 8.0f);
129+
CHECK_EQ(script.animations[2].blend_out, 0.0f);
130+
CHECK_EQ(script.animations[2].flags, zenkit::AnimationFlags::MOVE);
131+
CHECK_EQ(script.animations[2].model, "aniModel3");
132+
CHECK_EQ(script.animations[2].direction, zenkit::AnimationDirection::FORWARD);
133+
CHECK_EQ(script.animations[2].first_frame, 223);
134+
CHECK_EQ(script.animations[2].last_frame, 333);
135+
CHECK_EQ(script.animations[2].fps, 25.0f);
136+
CHECK_EQ(script.animations[2].speed, 0.0f);
137+
CHECK_EQ(script.animations[2].collision_volume_scale, 1.0f);
138+
139+
CHECK_EQ(script.animations[2].events.size(), 1);
140+
CHECK_EQ(script.animations[2].events[0].type, zenkit::MdsEventType::ITEM_CREATE);
141+
CHECK_EQ(script.animations[2].events[0].slot, "eventSlot");
142+
CHECK_EQ(script.animations[2].events[0].item, "eventItem");
143+
CHECK_EQ(script.animations[2].events[0].attached, false);
144+
145+
CHECK_EQ(script.animations[2].sfx_ground.size(), 1);
146+
CHECK_EQ(script.animations[2].sfx_ground[0].frame, 5);
147+
CHECK_EQ(script.animations[2].sfx_ground[0].name, "sfxGrndName");
148+
CHECK_EQ(script.animations[2].sfx_ground[0].empty_slot, false);
149+
150+
125151
CHECK_EQ(script.blends.size(), 3);
126152
CHECK_EQ(script.blends[0].name, "blendName1");
127153
CHECK_EQ(script.blends[0].next, "blendNext1");

tests/samples/waran.mds

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Model("TestModel") {
3939
aniBlend( ("blendName1" "blendNext1")
4040
aniBlend("blendName2" 113 "blendNext2")
4141

42+
ani("aniName3" 113 "aniNext3" 8.0 0 M. "aniModel3" F 223 333)
43+
*eventTag("DEF_CREATE_ITEM" "eventSlot" "eventItem")
44+
*eventSFXGrnd(5 "sfxGrndName")
45+
4246
aniBlend("blendName3" "blendNext3" 223.1 333.1) {
4347
*eventSFX(4 "sfxName2" R:67.4)
4448
}

0 commit comments

Comments
 (0)