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

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.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.

View File

@ -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<String, LVar> vars = new ObjectMap<>();
private Seq<VarEntry> 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<VarEntry> getEntries(){
return varEntries;
}

View File

@ -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;
}

View File

@ -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);
}