Skip to content

Commit

Permalink
Scripting|ResourceSystem: Added built-in Doomsday Script 'SavedSessio…
Browse files Browse the repository at this point in the history
…n' module

The SavedSession module provides access to the resource subsystem
functionality for savegame manipulation in Doomsday Script.

Presently, this consists of a native "convert" function binding,
allowing for automation of legacy savegame conversion in scripts.
  • Loading branch information
danij-deng committed Mar 28, 2014
1 parent fd8a9af commit f4b669d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -61,11 +61,14 @@
#endif

#include <de/App>
#include <de/ArrayValue>
#include <de/ByteRefArray>
#include <de/DirectoryFeed>
#include <de/game/SavedSession>
#include <de/Log>
#include <de/Module>
#include <de/NativeFile>
#include <de/NumberValue>
#include <de/Reader>
#include <de/Time>
#ifdef __CLIENT__
Expand Down Expand Up @@ -161,6 +164,16 @@ static detailvariantspecification_t &configureDetailTextureSpec(

#endif // __CLIENT__

/**
* Native Doomsday Script utility for executing a legacy savegame conversion.
*/
Value *Function_SavedSession_Convert(Context &, Function::ArgumentValues const &args)
{
String sourcePath = args[0]->asText();
String gameId = args[1]->asText();
return new NumberValue(App_ResourceSystem().convertLegacySavegame(sourcePath, gameId));
}

DENG2_PIMPL(ResourceSystem)
#ifdef __CLIENT__
, DENG2_OBSERVES(Games, Addition) // Saved session repository population
Expand Down Expand Up @@ -328,6 +341,9 @@ DENG2_PIMPL(ResourceSystem)
NativePath nativeSavePath;
game::SavedSessionRepository saveRepo;

Binder binder;
Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession)

Instance(Public *i)
: Base(i)
, defaultColorPalette (0)
Expand Down Expand Up @@ -378,6 +394,11 @@ DENG2_PIMPL(ResourceSystem)
#endif

#ifdef __CLIENT__
// Setup the SavedSession module.
binder.init(savedSessionModule)
<< DENG2_FUNC(SavedSession_Convert, "convert", "nativePath" << "gameId");
App::scriptSystem().addNativeModule("SavedSession", savedSessionModule);

App_Games().audienceForAddition() += this;

// Determine the root directory of the saved session repository.
Expand Down Expand Up @@ -1955,15 +1976,22 @@ DENG2_PIMPL(ResourceSystem)
sourceFolder.populate(Folder::PopulateOnlyThisFolder);
sourceFolder.setMode(Folder::ReadOnly);

//ArrayValue *pathList = 0;
DENG2_FOR_EACH_CONST(Folder::Contents, i, sourceFolder.contents())
{
if(namePattern.exactMatch(i->first.fileName()))
{
//if(!pathList) pathList = new ArrayValue;
//(*pathList) << TextValue(i->second->path());

self.convertLegacySavegame(i->second->path(), gameId);
}
}

/*if(pathList)
{
savedSessionModule.addArray(gameId + ".legacySavegames", pathList);
}*/
}
}
}
Expand Down

0 comments on commit f4b669d

Please sign in to comment.