VideoRec: Stop prerecording when /lua activates
authorWuzzy <Wuzzy2@mail.ru>
Mon, 22 Jul 2019 19:26:58 +0200
changeset 15267 22f2fd8a3d2c
parent 15266 b58f98bbc120
child 15268 07836d6bac21
VideoRec: Stop prerecording when /lua activates
hedgewars/uChat.pas
hedgewars/uVariables.pas
hedgewars/uVideoRec.pas
--- a/hedgewars/uChat.pas	Thu Jul 25 16:29:14 2019 +0300
+++ b/hedgewars/uChat.pas	Mon Jul 22 19:26:58 2019 +0200
@@ -35,7 +35,8 @@
 procedure TextInput(var event: TSDL_TextInputEvent);
 
 implementation
-uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uLocale;
+uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils, uLocale
+     {$IFDEF USE_VIDEO_RECORDING}, uVideoRec{$ENDIF};
 
 const MaxStrIndex = 27;
       MaxInputStrLen = 200;
@@ -548,7 +549,15 @@
 
     if (copy(s, 2, 3) = 'lua') then
         begin
+        LuaCmdUsed:= true;
         AddFileLog('/lua issued');
+{$IFDEF USE_VIDEO_RECORDING}
+        if flagPrerecording then
+            begin
+            AddFileLog('Force-stopping prerecording! Lua commands can not be recorded');
+            StopPreRecording;
+            end;
+{$ENDIF}
         if gameType <> gmtNet then
             begin
             liveLua:= (not liveLua);
--- a/hedgewars/uVariables.pas	Thu Jul 25 16:29:14 2019 +0300
+++ b/hedgewars/uVariables.pas	Mon Jul 22 19:26:58 2019 +0200
@@ -280,6 +280,9 @@
     // whether Lua requested to pause the clock
     LuaClockPaused: boolean;
 
+    // whether /lua command was used
+    LuaCmdUsed: boolean;
+
     MaskedSounds : array[TSound] of boolean;
 
     LastVoice : TVoice;
@@ -3007,6 +3010,8 @@
     LuaEndTurnRequested:= false;
     LuaNoEndTurnTaunts:= false;
 
+    LuaCmdUsed:= false;
+
     for t:= Low(TSound) to High(TSound) do
         MaskedSounds[t]:= false;
 
--- a/hedgewars/uVideoRec.pas	Thu Jul 25 16:29:14 2019 +0300
+++ b/hedgewars/uVideoRec.pas	Mon Jul 22 19:26:58 2019 +0200
@@ -48,7 +48,7 @@
 procedure freeModule;
 
 implementation
-uses uVariables, GLunit, SDLh, SysUtils, uUtils, uIO, uMisc, uTypes, uDebug;
+uses uVariables, GLunit, SDLh, SysUtils, uUtils, uSound, uIO, uMisc, uTypes, uDebug;
 
 type TAddFileLogRaw = procedure (s: pchar); cdecl;
 const AvwrapperLibName = 'libavwrapper';
@@ -286,6 +286,14 @@
 begin
     result:= 0;
     AddFileLog('BeginPreRecording');
+    // Videos don't work if /lua command was used, so we forbid them
+    if luaCmdUsed then
+        begin
+        // TODO: Show message to player
+        PlaySound(sndDenied);
+        AddFileLog('Pre-recording prevented; /lua command was used before');
+        exit;
+        end;
 
     thumbnailSaved:= false;
     RecPrefix:= 'hw-' + FormatDateTime('YYYY-MM-DD_HH-mm-ss-z', TDateTime(Now()));