Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
QUERYHANDLER(GenerateMap) | QUERYHANDLER(GenerateMap) | ||||
{ | { | ||||
try | try | ||||
{ | { | ||||
InitGame(); | InitGame(); | ||||
// Random map | // Random map | ||||
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue settings(cx); | JS::RootedValue settings(rq.cx); | ||||
scriptInterface.ParseJSON(*msg->settings, &settings); | scriptInterface.ParseJSON(*msg->settings, &settings); | ||||
scriptInterface.SetProperty(settings, "mapType", "random"); | scriptInterface.SetProperty(settings, "mapType", "random"); | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | rq, | ||||
&attrs, | &attrs, | ||||
"mapType", "random", | "mapType", "random", | ||||
"script", *msg->filename, | "script", *msg->filename, | ||||
"settings", settings); | "settings", settings); | ||||
StartGame(&attrs); | StartGame(&attrs); | ||||
msg->status = 0; | msg->status = 0; | ||||
} | } | ||||
catch (PSERROR_Game_World_MapLoadFailed&) | catch (PSERROR_Game_World_MapLoadFailed&) | ||||
{ | { | ||||
// Cancel loading | // Cancel loading | ||||
LDR_Cancel(); | LDR_Cancel(); | ||||
// Since map generation failed and we don't know why, use the blank map as a fallback | // Since map generation failed and we don't know why, use the blank map as a fallback | ||||
InitGame(); | InitGame(); | ||||
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
// Set up 8-element array of empty objects to satisfy init | // Set up 8-element array of empty objects to satisfy init | ||||
JS::RootedValue playerData(cx); | JS::RootedValue playerData(rq.cx); | ||||
ScriptInterface::CreateArray(cx, &playerData); | ScriptInterface::CreateArray(rq, &playerData); | ||||
for (int i = 0; i < 8; ++i) | for (int i = 0; i < 8; ++i) | ||||
{ | { | ||||
JS::RootedValue player(cx); | JS::RootedValue player(rq.cx); | ||||
ScriptInterface::CreateObject(cx, &player); | ScriptInterface::CreateObject(rq, &player); | ||||
scriptInterface.SetPropertyInt(playerData, i, player); | scriptInterface.SetPropertyInt(playerData, i, player); | ||||
} | } | ||||
JS::RootedValue settings(cx); | JS::RootedValue settings(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | rq, | ||||
&settings, | &settings, | ||||
"mapType", "scenario", | "mapType", "scenario", | ||||
"PlayerData", playerData); | "PlayerData", playerData); | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | rq, | ||||
&attrs, | &attrs, | ||||
"mapType", "scenario", | "mapType", "scenario", | ||||
"map", "maps/scenarios/_default", | "map", "maps/scenarios/_default", | ||||
"settings", settings); | "settings", settings); | ||||
StartGame(&attrs); | StartGame(&attrs); | ||||
msg->status = -1; | msg->status = -1; | ||||
} | } | ||||
} | } | ||||
MESSAGEHANDLER(LoadMap) | MESSAGEHANDLER(LoadMap) | ||||
{ | { | ||||
InitGame(); | InitGame(); | ||||
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
// Scenario | // Scenario | ||||
CStrW map = *msg->filename; | CStrW map = *msg->filename; | ||||
CStrW mapBase = map.BeforeLast(L".pmp"); // strip the file extension, if any | CStrW mapBase = map.BeforeLast(L".pmp"); // strip the file extension, if any | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | rq, | ||||
&attrs, | &attrs, | ||||
"mapType", "scenario", | "mapType", "scenario", | ||||
"map", mapBase); | "map", mapBase); | ||||
StartGame(&attrs); | StartGame(&attrs); | ||||
} | } | ||||
MESSAGEHANDLER(ImportHeightmap) | MESSAGEHANDLER(ImportHeightmap) | ||||
▲ Show 20 Lines • Show All 451 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator