diff options
author | mekolat <mekolat@users.noreply.github.com> | 2015-11-21 21:05:30 -0500 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2015-11-21 21:05:30 -0500 |
commit | 29b219f6a668b26442b0cfcf7fb9dcdf4b7d8c0d (patch) | |
tree | b13568df19333f7b21dedf739677c67b6c0bb904 | |
parent | f7c99c70de0f5bd77939966d085ad0da61bfd739 (diff) | |
parent | f6b949498ddb7a3738405f76cb300134d2653247 (diff) | |
download | tmwa-29b219f6a668b26442b0cfcf7fb9dcdf4b7d8c0d.tar.gz tmwa-29b219f6a668b26442b0cfcf7fb9dcdf4b7d8c0d.tar.bz2 tmwa-29b219f6a668b26442b0cfcf7fb9dcdf4b7d8c0d.tar.xz tmwa-29b219f6a668b26442b0cfcf7fb9dcdf4b7d8c0d.zip |
Merge pull request #182 from mekolat/warps
do not require a name for warps
-rw-r--r-- | src/ast/npc.cpp | 31 | ||||
-rw-r--r-- | src/ast/npc_test.cpp | 20 | ||||
-rw-r--r-- | src/map/npc-parse.cpp | 2 |
3 files changed, 23 insertions, 30 deletions
diff --git a/src/ast/npc.cpp b/src/ast/npc.cpp index 8d4a43e..dd01fa1 100644 --- a/src/ast/npc.cpp +++ b/src/ast/npc.cpp @@ -42,9 +42,9 @@ namespace npc static Result<Warp> parse_warp(io::LineSpan span, std::vector<Spanned<std::vector<Spanned<RString>>>>& bits) { - if (bits.size() != 4) + if (bits.size() != 3) { - return Err(span.error_str("expect 4 |component|s"_s)); + return Err(span.error_str("expect 3 |component|s"_s)); } if (bits[0].data.size() != 3) { @@ -52,13 +52,9 @@ namespace npc } assert(bits[1].data.size() == 1); assert(bits[1].data[0].data == "warp"_s); - if (bits[2].data.size() != 1) - { - return Err(bits[2].span.error_str("in |component 3| expect 1 ,component,s"_s)); - } - if (bits[3].data.size() != 5) + if (bits[2].data.size() != 5) { - return Err(bits[3].span.error_str("in |component 4| expect 5 ,component,s"_s)); + return Err(bits[2].span.error_str("in |component 3| expect 5 ,component,s"_s)); } Warp warp; @@ -66,18 +62,17 @@ namespace npc TRY_EXTRACT(bits[0].data[1], warp.x); TRY_EXTRACT(bits[0].data[2], warp.y); warp.key_span = bits[1].data[0].span; - TRY_EXTRACT(bits[2].data[0], warp.name); - if (bits[3].data[0].data == "-1"_s) - bits[3].data[0].data = "4294967295"_s; - TRY_EXTRACT(bits[3].data[0], warp.xs); + if (bits[2].data[0].data == "-1"_s) + bits[2].data[0].data = "4294967295"_s; + TRY_EXTRACT(bits[2].data[0], warp.xs); warp.xs.data += 2; - if (bits[3].data[1].data == "-1"_s) - bits[3].data[1].data = "4294967295"_s; - TRY_EXTRACT(bits[3].data[1], warp.ys); + if (bits[2].data[1].data == "-1"_s) + bits[2].data[1].data = "4294967295"_s; + TRY_EXTRACT(bits[2].data[1], warp.ys); warp.ys.data += 2; - TRY_EXTRACT(bits[3].data[2], warp.to_m); - TRY_EXTRACT(bits[3].data[3], warp.to_x); - TRY_EXTRACT(bits[3].data[4], warp.to_y); + TRY_EXTRACT(bits[2].data[2], warp.to_m); + TRY_EXTRACT(bits[2].data[3], warp.to_x); + TRY_EXTRACT(bits[2].data[4], warp.to_y); return Ok(std::move(warp)); } static diff --git a/src/ast/npc_test.cpp b/src/ast/npc_test.cpp index dadeba7..2ffff5e 100644 --- a/src/ast/npc_test.cpp +++ b/src/ast/npc_test.cpp @@ -89,9 +89,9 @@ namespace npc { // 1 2 3 4 //234567890123456789012345678901234567890123456789 - "map.gat,1,2|warp|To Other Map|3,4,other.gat,7,8"_s, - "map.gat,1,2|warp|To Other Map|3,4,other.gat,7,8\n"_s, - "map.gat,1,2|warp|To Other Map|3,4,other.gat,7,8{"_s, + "map.gat,1,2|warp|3,4,other.gat,7,8"_s, + "map.gat,1,2|warp|3,4,other.gat,7,8\n"_s, + "map.gat,1,2|warp|3,4,other.gat,7,8{"_s, // no optional fields in warp }; for (auto input : inputs) @@ -100,7 +100,7 @@ namespace npc auto res = TRY_UNWRAP(parse_top(lr), FAIL()); EXPECT_TRUE(res.get_success().is_some()); auto top = TRY_UNWRAP(std::move(res.get_success()), FAIL()); - EXPECT_SPAN(top.span, 1,1, 1,47); + EXPECT_SPAN(top.span, 1,1, 1,34); auto p = top.get_if<Warp>(); EXPECT_TRUE(p); if (p) @@ -112,17 +112,15 @@ namespace npc EXPECT_SPAN(p->y.span, 1,11, 1,11); EXPECT_EQ(p->y.data, 2); EXPECT_SPAN(p->key_span, 1,13, 1,16); - EXPECT_SPAN(p->name.span, 1,18, 1,29); - EXPECT_EQ(p->name.data, stringish<NpcName>("To Other Map"_s)); - EXPECT_SPAN(p->xs.span, 1,31, 1,31); + EXPECT_SPAN(p->xs.span, 1,18, 1,18); EXPECT_EQ(p->xs.data, 5); - EXPECT_SPAN(p->ys.span, 1,33, 1,33); + EXPECT_SPAN(p->ys.span, 1,20, 1,20); EXPECT_EQ(p->ys.data, 6); - EXPECT_SPAN(p->to_m.span, 1,35, 1,43); + EXPECT_SPAN(p->to_m.span, 1,22, 1,30); EXPECT_EQ(p->to_m.data, stringish<MapName>("other"_s)); - EXPECT_SPAN(p->to_x.span, 1,45, 1,45); + EXPECT_SPAN(p->to_x.span, 1,32, 1,32); EXPECT_EQ(p->to_x.data, 7); - EXPECT_SPAN(p->to_y.span, 1,47, 1,47); + EXPECT_SPAN(p->to_y.span, 1,34, 1,34); EXPECT_EQ(p->to_y.data, 8); } } diff --git a/src/map/npc-parse.cpp b/src/map/npc-parse.cpp index 9ee84d2..0bd23a9 100644 --- a/src/map/npc-parse.cpp +++ b/src/map/npc-parse.cpp @@ -153,7 +153,7 @@ bool npc_load_warp(ast::npc::Warp& warp) nd->dir = DIR::S; nd->flag = 0; nd->sit = DamageType::STAND; - nd->name = warp.name.data; + nd->name = stringish<NpcName>(STRPRINTF("w%c%i"_fmt, 6, nd->bl_id)); nd->npc_class = WARP_CLASS; nd->speed = 200_ms; |