diff --git a/modules/generative_grammar/grammar.cpp b/modules/generative_grammar/grammar.cpp index a93c2b9727..cb764f644f 100644 --- a/modules/generative_grammar/grammar.cpp +++ b/modules/generative_grammar/grammar.cpp @@ -114,7 +114,7 @@ bool CompositeRule::try_apply(Ref sentence) { } bool RepeatRuleUntilFailure::try_apply(Ref sentence) { - while (!this->rules.get(0)->try_apply(sentence)) { + while (this->rules.get(0)->try_apply(sentence)) { } return true; } @@ -127,17 +127,16 @@ void ReplaceRule::_bind_methods() { bool ReplaceRule::try_apply(Ref sentence) { ERR_FAIL_COND_V_EDMSG(this->results.size() == 0, false, "ReplaceRule::try_apply failed, no results in list"); Vector2i max{ sentence->get_size() - this->pattern->get_size() }; - bool any_success{ false }; for (Vector2i pos{ 0, 0 }; pos.y < max.y; ++pos.y) { for (; pos.x < max.x; ++pos.x) { if (sentence->check_match_at(pos, this->pattern)) { - any_success = true; sentence->write_subsentence(pos, this->results[Math::rand() % this->results.size()].first); // TODO pick based on weighed random + return true; } } pos.x = 0; } - return any_success; + return false; } void ReplaceRule::set_results_dict(Dictionary dict) { diff --git a/project/scenes/levels/dungeon.tscn b/project/scenes/levels/dungeon.tscn index d7be2d220e..32697091f5 100644 --- a/project/scenes/levels/dungeon.tscn +++ b/project/scenes/levels/dungeon.tscn @@ -1,17 +1,27 @@ [gd_scene format=3 uid="uid://cak2tf2adjv8j"] [sub_resource type="Sentence" id="Sentence_bb2w7"] -size = Vector2i(10, 10) -symbols_string = "BBBBBBBBBB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BuuuuuuuuB -BBBBBBBBBB" +size = Vector2i(20, 20) +symbols_string = "uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu +uuuuuuuuuuuuuuuuuuuu" [sub_resource type="Sentence" id="Sentence_wail4"] size = Vector2i(3, 1) @@ -25,15 +35,15 @@ symbols_string = "pxp" size = Vector2i(5, 5) symbols_string = "uuuuu uuuuu -pxpxp +xpxpx uuuuu uuuuu" [sub_resource type="Sentence" id="Sentence_yc5ro"] size = Vector2i(5, 5) symbols_string = "uuuuu -uppxu -pxupp +upxpu +xpupx uuuuu uuuuu" @@ -41,8 +51,8 @@ uuuuu" size = Vector2i(5, 5) symbols_string = "uuuuu uuuuu -pxupp -uppxu +xpupx +upxpu uuuuu" [node name="Dungeon" type="Node3D" unique_id=719313039]