Skip to content

Commit 85842ea

Browse files
authored
when pasting a condition into an empty leaderboard editor, add measured flag to prevent serializing comparison (#1322)
1 parent 9bc4e43 commit 85842ea

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/ui/viewmodels/TriggerViewModel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,17 @@ void TriggerViewModel::PasteFromClipboard()
330330
return;
331331
}
332332

333-
const auto nResult = AppendMemRefChain(ra::util::String::Narrow(sClipboardText));
333+
std::string sNarrowText = ra::util::String::Narrow(sClipboardText);
334+
if (IsValue() && Conditions().Count() == 0 && sNarrowText.find(':') == std::string::npos)
335+
{
336+
// if pasting something that looks like a legacy-formatted value into the value editor,
337+
// and the value editor is empty, explicitly add a "M:" so it doesn't get parse as a
338+
// legacy value. this prevents pushing a legacy value with a comparison to the server,
339+
// which can prevent the leaderboard from functioning in rcheevos 12.0 and 12.1.
340+
sNarrowText.insert(0, "M:");
341+
}
342+
343+
const auto nResult = AppendMemRefChain(sNarrowText);
334344
if (nResult != RC_OK)
335345
{
336346
if (nResult == RC_MULTIPLE_GROUPS)

tests/ui/viewmodels/TriggerViewModel_Tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,23 @@ TEST_CLASS(TriggerViewModel_Tests)
574574
Assert::IsTrue(bDialogShown);
575575
}
576576

577+
TEST_METHOD(TestPasteFromClipboardValueWithComparison)
578+
{
579+
TriggerViewModelHarness vmTrigger;
580+
Parse(vmTrigger, "");
581+
vmTrigger.SetIsValue(true);
582+
583+
vmTrigger.mockClipboard.SetText(L"0xH1234<100");
584+
vmTrigger.PasteFromClipboard();
585+
586+
// the parser will see "0xH1234<100" as a legacy value and truncate it to "0xH1234" for display.
587+
// but the serialized value will still have the "<100" as it was part of the pasted text.
588+
// expect the paste operation to convert it to a non-legacy value
589+
590+
Assert::AreEqual({ 1U }, vmTrigger.Conditions().Count());
591+
Assert::AreEqual(std::string("M:0xH1234<100"), vmTrigger.Serialize());
592+
}
593+
577594
TEST_METHOD(TestPasteFromClipboardInvalidSyntax)
578595
{
579596
TriggerViewModelHarness vmTrigger;

0 commit comments

Comments
 (0)