Ticket #2385: modsloaded.diff

File modsloaded.diff, 5.8 KB (added by mimo, 10 years ago)
  • binaries/data/mods/public/gui/savedgames/load.js

     
    33    var gameSelection = Engine.GetGUIObjectByName("gameSelection");
    44
    55    var savedGames = Engine.GetSavedGames();
     6
     7    var sameMods = Engine.GetGUIObjectByName("modsSelection").checked;
     8    if (sameMods)
     9    {
     10        var modsLoaded = Engine.GetModsLoaded();
     11        savedGames = savedGames.filter(function(game) {
     12            if (!game.metadata.mods)
     13                return true;     // temporary, for backward compatibility
     14            var gameMods = game.metadata.mods;
     15            if (modsLoaded.length != gameMods.length)
     16                return false;
     17            for (var i = 0; i < modsLoaded.length; ++i)
     18                if (modsLoaded[i] != gameMods[i])
     19                    return false;
     20            return true;
     21        });
     22    }
     23
    624    if (savedGames.length == 0)
    725    {
    826        gameSelection.list = [ "No saved games found" ];
  • binaries/data/mods/public/gui/savedgames/load.xml

     
    2121            size="24 24 100%-24 100%-100">
    2222        </object>
    2323
     24        <object type="image" size="50 100%-90 100%-50 100%-70">
     25            <object name="modsSelection" size="0 10% 16 90%" type="checkbox" style="StoneCrossBox">
     26                <action on="Load">this.checked = true;</action>
     27                <action on="Press">init();</action>
     28            </object>
     29            <object size="25 0 100% 100%" type="text" style="LeftLabelText" ghost="true">Show only games with the current mod</object>
     30        </object>
     31
    2432        <object name="loadGameButton" type="button" size="0%+25 100%-60 33%+10 100%-32" style="StoneButton">
    2533            Load
    2634            <action on="Press">loadGame();</action>
  • source/gui/scripting/ScriptFunctions.cpp

     
    194194        g_Game->SetPlayerID(id);
    195195}
    196196
     197std::vector<std::string> GetModsLoaded(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
     198{
     199    return g_modsLoaded;
     200}
     201
    197202void StartNetworkGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
    198203{
    199204    ENSURE(g_NetServer);
     
    841846    scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
    842847    scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
    843848    scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
     849    scriptInterface.RegisterFunction<std::vector<std::string>, &GetModsLoaded>("GetModsLoaded");
    844850    scriptInterface.RegisterFunction<CScriptVal, VfsPath, &LoadMapSettings>("LoadMapSettings");
    845851    scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings");
    846852    scriptInterface.RegisterFunction<float, &CameraGetX>("CameraGetX");
  • source/main.cpp

     
    421421    if(ran_atlas)
    422422        return;
    423423
     424    g_modsLoaded.clear();
    424425    // run non-visual simulation replay if requested
    425426    if (args.Has("replay"))
    426427    {
     
    429430        g_VFS = CreateVfs(20 * MiB);
    430431        g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);
    431432        g_VFS->Mount(L"", paths.RData()/"mods"/"public", VFS_MOUNT_MUST_EXIST);
    432 
    433433        {
    434434            CReplayPlayer replay;
    435435            replay.Load(args.Get("replay"));
     
    464464    const double res = timer_Resolution();
    465465    g_frequencyFilter = CreateFrequencyFilter(res, 30.0);
    466466
     467    std::vector<CStr> modsLoaded = args.GetMultiple("mod");
     468    for (size_t i = 0; i < modsLoaded.size(); ++i)
     469        g_modsLoaded.push_back((std::string)modsLoaded[i]);
    467470    // run the game
    468471    Init(args, 0);
    469472    InitGraphics(args, 0);
  • source/ps/GameSetup/Config.cpp

     
    7676// If non-empty, specified map will be automatically loaded
    7777CStr g_AutostartMap = "";
    7878
     79std::vector<std::string> g_modsLoaded;
    7980
     81
    8082//----------------------------------------------------------------------------
    8183// config
    8284//----------------------------------------------------------------------------
  • source/ps/GameSetup/Config.h

     
    9090
    9191extern CStrW g_CursorName;
    9292
     93// list of mods currently loaded
     94extern std::vector<std::string> g_modsLoaded;
     95
    9396class CmdLineArgs;
    9497extern void CONFIG_Init(const CmdLineArgs& args);
    9598
  • source/ps/SavedGame.cpp

     
    2424#include "lib/file/archive/archive_zip.h"
    2525#include "ps/CLogger.h"
    2626#include "ps/Filesystem.h"
     27#include "ps/GameSetup/Config.h"
    2728#include "scriptinterface/ScriptInterface.h"
    2829#include "simulation2/Simulation2.h"
    2930
     
    7677    simulation.GetScriptInterface().Eval("({})", metadata);
    7778    simulation.GetScriptInterface().SetProperty(metadata.get(), "version_major", SAVED_GAME_VERSION_MAJOR);
    7879    simulation.GetScriptInterface().SetProperty(metadata.get(), "version_minor", SAVED_GAME_VERSION_MINOR);
     80    simulation.GetScriptInterface().SetProperty(metadata.get(), "mods", g_modsLoaded);
    7981    simulation.GetScriptInterface().SetProperty(metadata.get(), "time", (double)now);
    8082    simulation.GetScriptInterface().SetProperty(metadata.get(), "player", playerID);
    8183    simulation.GetScriptInterface().SetProperty(metadata.get(), "initAttributes", simulation.GetInitAttributes());