MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / GameActionResultToJS

Method GameActionResultToJS

src/openrct2/scripting/ScriptEngine.cpp:1464–1530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1462}
1463
1464JSValue ScriptEngine::GameActionResultToJS(
1465 JSContext* ctx, const GameActions::GameAction& action, const GameActions::Result& result)
1466{
1467 JSValue obj = JS_NewObject(ctx);
1468
1469 JS_SetPropertyStr(
1470 ctx, obj, "error", JS_NewInt32(ctx, static_cast<std::underlying_type_t<GameActions::Status>>(result.error)));
1471 if (result.error != GameActions::Status::ok)
1472 {
1473 JS_SetPropertyStr(ctx, obj, "errorTitle", JSFromStdString(ctx, result.getErrorTitle()));
1474 JS_SetPropertyStr(ctx, obj, "errorMessage", JSFromStdString(ctx, result.getErrorMessage()));
1475 }
1476
1477 if (result.cost != kMoney64Undefined)
1478 {
1479 JS_SetPropertyStr(ctx, obj, "cost", JS_NewInt64(ctx, result.cost));
1480 }
1481 if (!result.position.IsNull())
1482 {
1483 JS_SetPropertyStr(ctx, obj, "position", ToJSValue(ctx, result.position));
1484 }
1485 if (result.expenditure != ExpenditureType::count)
1486 {
1487 JS_SetPropertyStr(ctx, obj, "expenditureType", JSFromStdString(ctx, ExpenditureTypeToString(result.expenditure)));
1488 }
1489
1490 if (result.error == GameActions::Status::ok)
1491 {
1492 // RideCreateAction only
1493 if (action.GetType() == GameCommand::CreateRide)
1494 {
1495 const auto rideIndex = result.getData<RideId>();
1496 JS_SetPropertyStr(ctx, obj, "ride", JS_NewInt32(ctx, rideIndex.ToUnderlying()));
1497 }
1498 // StaffHireNewAction only
1499 else if (action.GetType() == GameCommand::HireNewStaffMember)
1500 {
1501 const auto actionResult = result.getData<GameActions::StaffHireNewActionResult>();
1502 if (!actionResult.StaffEntityId.IsNull())
1503 {
1504 JS_SetPropertyStr(ctx, obj, "peep", JS_NewInt32(ctx, actionResult.StaffEntityId.ToUnderlying()));
1505 }
1506 }
1507 // BannerPlaceAction, LargeSceneryPlaceAction, WallPlaceAction
1508 auto bannerId = BannerIndex::GetNull();
1509 switch (action.GetType())
1510 {
1511 case GameCommand::PlaceBanner:
1512 bannerId = result.getData<GameActions::BannerPlaceActionResult>().bannerId;
1513 break;
1514 case GameCommand::PlaceLargeScenery:
1515 bannerId = result.getData<GameActions::LargeSceneryPlaceActionResult>().bannerId;
1516 break;
1517 case GameCommand::PlaceWall:
1518 bannerId = result.getData<GameActions::WallPlaceActionResult>().BannerId;
1519 break;
1520 default:
1521 break;

Callers 1

Calls 7

JSFromStdStringFunction · 0.85
getErrorTitleMethod · 0.80
getErrorMessageMethod · 0.80
ToUnderlyingMethod · 0.80
ToJSValueFunction · 0.70
IsNullMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected