Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | try | ||||
// Random map | // Random map | ||||
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue settings(cx); | JS::RootedValue settings(cx); | ||||
scriptInterface.ParseJSON(*msg->settings, &settings); | scriptInterface.ParseJSON(*msg->settings, &settings); | ||||
scriptInterface.SetProperty(settings, "mapType", std::string("random")); | scriptInterface.SetProperty(settings, "mapType", "random"); | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(cx); | ||||
scriptInterface.CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&attrs, | &attrs, | ||||
"mapType", std::string("random"), | "mapType", "random", | ||||
"script", std::wstring(*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(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | 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(cx); | ||||
scriptInterface.CreateArray(&playerData); | ScriptInterface::CreateArray(cx, &playerData); | ||||
for (int i = 0; i < 8; ++i) | for (int i = 0; i < 8; ++i) | ||||
{ | { | ||||
JS::RootedValue player(cx); | JS::RootedValue player(cx); | ||||
scriptInterface.CreateObject(&player); | ScriptInterface::CreateObject(cx, &player); | ||||
scriptInterface.SetPropertyInt(playerData, i, player); | scriptInterface.SetPropertyInt(playerData, i, player); | ||||
} | } | ||||
JS::RootedValue settings(cx); | JS::RootedValue settings(cx); | ||||
scriptInterface.CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&settings, | &settings, | ||||
"mapType", std::string("scenario"), | "mapType", "scenario", | ||||
"PlayerData", playerData); | "PlayerData", playerData); | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(cx); | ||||
scriptInterface.CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&attrs, | &attrs, | ||||
"mapType", std::string("scenario"), | "mapType", "scenario", | ||||
"map", std::wstring(L"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(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | 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(cx); | ||||
scriptInterface.CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&attrs, | &attrs, | ||||
"mapType", std::string("scenario"), | "mapType", "scenario", | ||||
"map", std::wstring(mapBase)); | "map", mapBase); | ||||
StartGame(&attrs); | StartGame(&attrs); | ||||
} | } | ||||
MESSAGEHANDLER(ImportHeightmap) | MESSAGEHANDLER(ImportHeightmap) | ||||
{ | { | ||||
std::vector<u16> heightmap_source; | std::vector<u16> heightmap_source; | ||||
if (LoadHeightmapImageOs(*msg->filename, heightmap_source) != INFO::OK) | if (LoadHeightmapImageOs(*msg->filename, heightmap_source) != INFO::OK) | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator