From 27f20b7a363526d5511b29387f1287c12a28494c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 3 Aug 2024 00:51:31 -0400 Subject: [PATCH] Better implementation of #10047 --- core/assets/bundles/bundle.properties | 2 +- core/src/mindustry/logic/GlobalVars.java | 7 ++++++- core/src/mindustry/logic/LExecutor.java | 13 +++++++++---- core/src/mindustry/logic/LStatements.java | 6 ++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index f551aac13c..9488bd9f50 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2376,7 +2376,7 @@ lst.setrate = Set processor execution speed in instructions/tick. lst.fetch = Lookup units, cores, players or buildings by index.\nIndices start at 0 and end at their returned count. lst.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting. lst.setrule = Set a game rule. -lst.flushmessage = Display a message on the screen from the text buffer.\nWill wait until the previous message finishes. +lst.flushmessage = Display a message on the screen from the text buffer.\nIf the success result variable is [accent]@wait[],\nwill wait until the previous message finishes.\nOtherwise, outputs whether displaying the message succeeded. lst.cutscene = Manipulate the player camera. lst.setflag = Set a global flag that can be read by all processors. lst.getflag = Check if a global flag is set. diff --git a/core/src/mindustry/logic/GlobalVars.java b/core/src/mindustry/logic/GlobalVars.java index ffafbc9437..3b954d986d 100644 --- a/core/src/mindustry/logic/GlobalVars.java +++ b/core/src/mindustry/logic/GlobalVars.java @@ -27,7 +27,7 @@ public class GlobalVars{ public static final Rand rand = new Rand(); //non-constants that depend on state - private static LVar varTime, varTick, varSecond, varMinute, varWave, varWaveTime, varMapW, varMapH, varServer, varClient, varClientLocale, varClientUnit, varClientName, varClientTeam, varClientMobile; + private static LVar varTime, varTick, varSecond, varMinute, varWave, varWaveTime, varMapW, varMapH, varWait, varServer, varClient, varClientLocale, varClientUnit, varClientName, varClientTeam, varClientMobile; private ObjectMap vars = new ObjectMap<>(); private Seq varEntries = new Seq<>(); @@ -73,6 +73,7 @@ public class GlobalVars{ varMapW = putEntry("@mapw", 0); varMapH = putEntry("@maph", 0); + varWait = putEntry("@wait", null); putEntryOnly("sectionNetwork"); @@ -209,6 +210,10 @@ public class GlobalVars{ } } + public LVar waitVar(){ + return varWait; + } + public Seq getEntries(){ return varEntries; } diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 3b7f8c08d3..4a977b3dcd 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -42,7 +42,6 @@ public class LExecutor{ maxDisplayBuffer = 1024, maxTextBuffer = 400; - public LInstruction[] instructions = {}; /** Non-constant variables used for network sync */ public LVar[] vars = {}; @@ -1601,7 +1600,7 @@ public class LExecutor{ public void run(LExecutor exec){ //set default to success outSuccess.setnum(1); - if(headless && type != MessageType.mission) { + if(headless && type != MessageType.mission){ exec.textBuffer.setLength(0); return; } @@ -1611,8 +1610,14 @@ public class LExecutor{ type == MessageType.notify && ui.hudfrag.hasToast() || type == MessageType.toast && ui.hasAnnouncement() ){ - //set outSuccess=false to let user retry. - outSuccess.setnum(0); + //backwards compatibility; if it is @wait, block execution + if(outSuccess == logicVars.waitVar()){ + exec.counter.numval--; + exec.yield = true; + }else{ + //set outSuccess=false to let user retry. + outSuccess.setnum(0); + } return; } diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 7c8bd8558f..a27e35304b 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1594,7 +1594,7 @@ public class LStatements{ @RegisterStatement("message") public static class FlushMessageStatement extends LStatement{ public MessageType type = MessageType.announce; - public String duration = "3", outSuccess = "success"; + public String duration = "3", outSuccess = "@wait"; @Override public void build(Table table){ @@ -1616,9 +1616,11 @@ public class LStatements{ case announce, toast -> { table.add(" for "); fields(table, duration, str -> duration = str); - table.add(" secs "); + table.add(" sec "); } } + row(table); + table.add(" success "); fields(table, outSuccess, str -> outSuccess = str); }