Better implementation of #10047

This commit is contained in:
Anuken
2024-08-03 00:51:31 -04:00
parent c1309c4701
commit 27f20b7a36
4 changed files with 20 additions and 8 deletions
+1 -1
View File
@@ -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.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.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting.
lst.setrule = Set a game rule. 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.cutscene = Manipulate the player camera.
lst.setflag = Set a global flag that can be read by all processors. lst.setflag = Set a global flag that can be read by all processors.
lst.getflag = Check if a global flag is set. lst.getflag = Check if a global flag is set.
+6 -1
View File
@@ -27,7 +27,7 @@ public class GlobalVars{
public static final Rand rand = new Rand(); public static final Rand rand = new Rand();
//non-constants that depend on state //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<String, LVar> vars = new ObjectMap<>(); private ObjectMap<String, LVar> vars = new ObjectMap<>();
private Seq<VarEntry> varEntries = new Seq<>(); private Seq<VarEntry> varEntries = new Seq<>();
@@ -73,6 +73,7 @@ public class GlobalVars{
varMapW = putEntry("@mapw", 0); varMapW = putEntry("@mapw", 0);
varMapH = putEntry("@maph", 0); varMapH = putEntry("@maph", 0);
varWait = putEntry("@wait", null);
putEntryOnly("sectionNetwork"); putEntryOnly("sectionNetwork");
@@ -209,6 +210,10 @@ public class GlobalVars{
} }
} }
public LVar waitVar(){
return varWait;
}
public Seq<VarEntry> getEntries(){ public Seq<VarEntry> getEntries(){
return varEntries; return varEntries;
} }
+9 -4
View File
@@ -42,7 +42,6 @@ public class LExecutor{
maxDisplayBuffer = 1024, maxDisplayBuffer = 1024,
maxTextBuffer = 400; maxTextBuffer = 400;
public LInstruction[] instructions = {}; public LInstruction[] instructions = {};
/** Non-constant variables used for network sync */ /** Non-constant variables used for network sync */
public LVar[] vars = {}; public LVar[] vars = {};
@@ -1601,7 +1600,7 @@ public class LExecutor{
public void run(LExecutor exec){ public void run(LExecutor exec){
//set default to success //set default to success
outSuccess.setnum(1); outSuccess.setnum(1);
if(headless && type != MessageType.mission) { if(headless && type != MessageType.mission){
exec.textBuffer.setLength(0); exec.textBuffer.setLength(0);
return; return;
} }
@@ -1611,8 +1610,14 @@ public class LExecutor{
type == MessageType.notify && ui.hudfrag.hasToast() || type == MessageType.notify && ui.hudfrag.hasToast() ||
type == MessageType.toast && ui.hasAnnouncement() type == MessageType.toast && ui.hasAnnouncement()
){ ){
//set outSuccess=false to let user retry. //backwards compatibility; if it is @wait, block execution
outSuccess.setnum(0); if(outSuccess == logicVars.waitVar()){
exec.counter.numval--;
exec.yield = true;
}else{
//set outSuccess=false to let user retry.
outSuccess.setnum(0);
}
return; return;
} }
+4 -2
View File
@@ -1594,7 +1594,7 @@ public class LStatements{
@RegisterStatement("message") @RegisterStatement("message")
public static class FlushMessageStatement extends LStatement{ public static class FlushMessageStatement extends LStatement{
public MessageType type = MessageType.announce; public MessageType type = MessageType.announce;
public String duration = "3", outSuccess = "success"; public String duration = "3", outSuccess = "@wait";
@Override @Override
public void build(Table table){ public void build(Table table){
@@ -1616,9 +1616,11 @@ public class LStatements{
case announce, toast -> { case announce, toast -> {
table.add(" for "); table.add(" for ");
fields(table, duration, str -> duration = str); fields(table, duration, str -> duration = str);
table.add(" secs "); table.add(" sec ");
} }
} }
row(table);
table.add(" success "); table.add(" success ");
fields(table, outSuccess, str -> outSuccess = str); fields(table, outSuccess, str -> outSuccess = str);
} }