From 54429cd23bf7118aac2e475d0221fe927f29ba32 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 24 Jan 2024 18:31:04 +0100 Subject: [PATCH] Parse special characters that have been put back as names too --- .../mwscript/test_scripts.cpp | 28 +++++++++++++++++++ components/compiler/scanner.cpp | 15 +++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/openmw_test_suite/mwscript/test_scripts.cpp b/apps/openmw_test_suite/mwscript/test_scripts.cpp index dbed262235..0de542bdc6 100644 --- a/apps/openmw_test_suite/mwscript/test_scripts.cpp +++ b/apps/openmw_test_suite/mwscript/test_scripts.cpp @@ -326,6 +326,8 @@ End)mwscript"; Addtopic -spells... Addtopic -magicka... +player->PositionCell, -97274, -94273, 8064, -12,-12 + End)mwscript"; const std::string sIssue4061 = R"mwscript(Begin 01_Rz_neuvazhay-koryto2 @@ -763,7 +765,33 @@ End)mwscript"; mTopics.erase(mTopics.begin()); } }; + class PositionCell : public Interpreter::Opcode0 + { + public: + void execute(Interpreter::Runtime& runtime) + { + std::string_view target = runtime.getStringLiteral(runtime[0].mInteger); + runtime.pop(); + Interpreter::Type_Float x = runtime[0].mFloat; + runtime.pop(); + Interpreter::Type_Float y = runtime[0].mFloat; + runtime.pop(); + Interpreter::Type_Float z = runtime[0].mFloat; + runtime.pop(); + Interpreter::Type_Float zRot = runtime[0].mFloat; + runtime.pop(); + std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); + runtime.pop(); + EXPECT_EQ(target, "player"); + EXPECT_EQ(x, -97274); + EXPECT_EQ(y, -94273); + EXPECT_EQ(z, 8064); + EXPECT_EQ(zRot, -12); + EXPECT_EQ(cellID, "-12"); + } + }; installOpcode(Compiler::Dialogue::opcodeAddTopic, topics); + installOpcode(Compiler::Transformation::opcodePositionCellExplicit); TestInterpreterContext context; run(*script, context); EXPECT_TRUE(topics.empty()); diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 4794f569b5..49f3999740 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -63,9 +63,22 @@ namespace Compiler switch (mPutback) { case Putback_Special: - + { mPutback = Putback_None; + // Replicate behaviour from scanSpecial so putting something back doesn't change the way it's handled + if (mExpectName && (mPutbackCode == S_member || mPutbackCode == S_minus)) + { + mExpectName = false; + bool cont = false; + bool tolerant = mTolerantNames; + mTolerantNames = true; + MultiChar c{ mPutbackCode == S_member ? '.' : '-' }; + scanName(c, parser, cont); + mTolerantNames = tolerant; + return cont; + } return parser.parseSpecial(mPutbackCode, mPutbackLoc, *this); + } case Putback_Integer: