hedgewars/uScript.pas
changeset 10150 fa5c83fd0ad9
parent 10143 3636106f5b70
child 10210 1a6b9a98147c
--- a/hedgewars/uScript.pas	Fri Feb 21 13:31:16 2014 +0400
+++ b/hedgewars/uScript.pas	Sun Feb 23 10:06:58 2014 -0500
@@ -35,6 +35,7 @@
 procedure ScriptClearStack;
 
 procedure ScriptLoad(name : shortstring);
+procedure ScriptOnPreviewInit;
 procedure ScriptOnGameInit;
 procedure ScriptOnScreenResize;
 procedure ScriptSetInteger(name : shortstring; value : LongInt);
@@ -2094,6 +2095,27 @@
     lua_pop(luaState, 1);
 end;
 
+procedure ScriptOnPreviewInit;
+var i, j, k: LongInt;
+begin
+// not required if there is no script to run
+if not ScriptLoaded then
+    exit;
+
+ScriptSetString('Seed', cSeed);
+ScriptSetInteger('TemplateFilter', cTemplateFilter);
+ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
+ScriptSetInteger('MapGen', cMapGen);
+
+ScriptCall('onPreviewInit');
+
+// pop game variables
+ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
+cTemplateFilter  := ScriptGetInteger('TemplateFilter');
+LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
+cMapGen          := ScriptGetInteger('MapGen');
+end;
+
 procedure ScriptOnGameInit;
 var i, j, k: LongInt;
 begin
@@ -2251,7 +2273,7 @@
     lua_pcall(luaState, 0, 0, 0);
     ScriptLoaded:= true
     end;
-    hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
+hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
 end;
 
 procedure SetGlobals;