Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
authornemo
Sun, 23 Feb 2014 10:06:58 -0500
changeset 10150 fa5c83fd0ad9
parent 10149 017ca6054845
child 10151 8fc1459a9f54
child 10152 15e9bb6fcab2
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
QTfrontend/net/hwmap.cpp
QTfrontend/net/hwmap.h
QTfrontend/ui/widget/gamecfgwidget.cpp
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
hedgewars/hwengine.pas
hedgewars/uMisc.pas
hedgewars/uScript.pas
share/hedgewars/Data/Graphics/amRubber.png
share/hedgewars/Data/Scripts/Multiplayer/ShoppaMap.lua
--- a/QTfrontend/net/hwmap.cpp	Fri Feb 21 13:31:16 2014 +0400
+++ b/QTfrontend/net/hwmap.cpp	Sun Feb 23 10:06:58 2014 -0500
@@ -34,9 +34,10 @@
     return !m_hasStarted;
 }
 
-void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData)
+void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData, QString & script)
 {
     m_seed = seed;
+    m_script = script;
     templateFilter = filter;
     m_mapgen = mapgen;
     m_maze_size = maze_size;
@@ -73,6 +74,10 @@
     SendIPC(QString("eseed %1").arg(m_seed).toUtf8());
     SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8());
     SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8());
+    if (m_script.length())
+    {
+        SendIPC(QString("escript Scripts/Multiplayer/%1.lua").arg(m_script).toUtf8());
+    }
 
     switch (m_mapgen)
     {
--- a/QTfrontend/net/hwmap.h	Fri Feb 21 13:31:16 2014 +0400
+++ b/QTfrontend/net/hwmap.h	Sun Feb 23 10:06:58 2014 -0500
@@ -41,7 +41,7 @@
     public:
         HWMap(QObject *parent = 0);
         virtual ~HWMap();
-        void getImage(const QString & seed, int templateFilter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData);
+        void getImage(const QString & seed, int templateFilter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData, QString & script);
         bool couldBeRemoved();
 
     protected:
@@ -55,6 +55,7 @@
 
     private:
         QString m_seed;
+        QString m_script;
         int templateFilter;
         MapGenerator m_mapgen;
         int m_maze_size;
--- a/QTfrontend/ui/widget/gamecfgwidget.cpp	Fri Feb 21 13:31:16 2014 +0400
+++ b/QTfrontend/ui/widget/gamecfgwidget.cpp	Sun Feb 23 10:06:58 2014 -0500
@@ -445,6 +445,7 @@
         }
         if (param == "SCRIPT")
         {
+            pMapContainer->setScript(value);
             Scripts->setCurrentIndex(Scripts->findText(value));
             return;
         }
@@ -644,6 +645,14 @@
         WeaponsName->setEnabled(true);
         bindEntries->setEnabled(true);
     }
+    if (!index)
+    {
+        pMapContainer->setScript(QString(""));
+    }
+    else
+    {
+        pMapContainer->setScript(name);
+    }
     emit paramChanged("SCRIPT", QStringList(name));
 }
 
--- a/QTfrontend/ui/widget/mapContainer.cpp	Fri Feb 21 13:31:16 2014 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Sun Feb 23 10:06:58 2014 -0500
@@ -59,6 +59,7 @@
     m_previewEnabled = false;
     m_missionsViewSetup = false;
     m_staticViewSetup = false;
+    m_script = QString("");
 
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
@@ -315,7 +316,8 @@
                    getTemplateFilter(),
                    get_mapgen(),
                    getMazeSize(),
-                   getDrawnMapData()
+                   getDrawnMapData(),
+                   m_script
                   );
 
     setHHLimit(0);
@@ -413,6 +415,13 @@
         updatePreview();
 }
 
+void HWMapContainer::setScript(const QString & script)
+{
+    m_script = script;
+    if ((m_mapInfo.type == MapModel::GeneratedMap) || (m_mapInfo.type == MapModel::GeneratedMaze))
+        updatePreview();
+}
+
 void HWMapContainer::intSetMap(const QString & map)
 {
     if (map == "+rnd+")
--- a/QTfrontend/ui/widget/mapContainer.h	Fri Feb 21 13:31:16 2014 +0400
+++ b/QTfrontend/ui/widget/mapContainer.h	Sun Feb 23 10:06:58 2014 -0500
@@ -71,6 +71,7 @@
     public slots:
         void askForGeneratedPreview();
         void setSeed(const QString & seed);
+        void setScript(const QString & script);
         void setMap(const QString & map);
         void setTheme(const QString & theme);
         void setTemplateFilter(int);
@@ -124,6 +125,7 @@
         ThemeModel * m_themeModel;
         HWMap* pMap;
         QString m_seed;
+        QString m_script;
         QPushButton* seedSet;
         QLabel* seedLabel;
         int hhLimit;
--- a/hedgewars/hwengine.pas	Fri Feb 21 13:31:16 2014 +0400
+++ b/hedgewars/hwengine.pas	Sun Feb 23 10:06:58 2014 -0500
@@ -458,10 +458,11 @@
     uLand.initModule;               // computes land
     uLandPainted.initModule;        // computes drawn land
     uIO.initModule;                 // sets up sockets
+    uPhysFSLayer.initModule;
+    uScript.initModule;
 
     if complete then
     begin
-        uPhysFSLayer.initModule;
         uTextures.initModule;
 {$IFDEF ANDROID}GLUnit.initModule;{$ENDIF}
 {$IFDEF USE_TOUCH_INTERFACE}uTouch.initModule;{$ENDIF}
@@ -478,7 +479,6 @@
         uInputHandler.initModule;
         uMisc.initModule;
         uLandTexture.initModule;    //stub
-        uScript.initModule;
         uSound.initModule;
         uStats.initModule;
         uStore.initModule;
@@ -543,6 +543,7 @@
     IPCWaitPongEvent;
     TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
 
+    ScriptOnPreviewInit;
     GenPreview(Preview);
     WriteLnToConsole('Sending preview...');
     SendIPCRaw(@Preview, sizeof(Preview));
--- a/hedgewars/uMisc.pas	Fri Feb 21 13:31:16 2014 +0400
+++ b/hedgewars/uMisc.pas	Sun Feb 23 10:06:58 2014 -0500
@@ -300,6 +300,7 @@
 end;
 
 {$IFDEF SDL2}
+// FIXME - pretty sure this is not handling endianness correctly like the SDL1 is
 const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
 {$ELSE}
 const format: TSDL_PixelFormat = (
--- 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;
Binary file share/hedgewars/Data/Graphics/amRubber.png has changed
--- a/share/hedgewars/Data/Scripts/Multiplayer/ShoppaMap.lua	Fri Feb 21 13:31:16 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/ShoppaMap.lua	Sun Feb 23 10:06:58 2014 -0500
@@ -352,6 +352,10 @@
     end
 end
 
+function onPreviewInit()
+onGameInit()
+end
+
 function onGameInit()
     MapGen = 2
     TemplateFilter = 0