From 62bb60a00220aa59df684502da50ad7fa254747c Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Sun, 2 Jun 2024 09:54:07 -0700 Subject: [PATCH] Add "direction" JS field to Structure objects (#3508) Adds a "direction" field to JS structure objects, which represents the direction the structure is facing (from 0 to 3, in 90 degree increments). --- doc/js-objects.md | 1 + src/quickjs_backend.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/doc/js-objects.md b/doc/js-objects.md index a026e21c89f..c1e04993072 100644 --- a/doc/js-objects.md +++ b/doc/js-objects.md @@ -25,6 +25,7 @@ In addition, the following properties are defined: * ```status``` The completeness status of the structure. It will be one of ```BEING_BUILT``` and ```BUILT```. * ```type``` The type will always be ```STRUCTURE```. * ```cost``` What it would cost to build this structure. (3.2+ only) +* ```direction``` The direction the structure is facing. (4.5+ only) * ```stattype``` The stattype defines the type of structure. It will be one of ```HQ```, ```FACTORY```, ```POWER_GEN```, ```RESOURCE_EXTRACTOR```, ```LASSAT```, ```DEFENSE```, ```WALL```, ```RESEARCH_LAB```, ```REPAIR_FACILITY```, ```CYBORG_FACTORY```, ```VTOL_FACTORY```, ```REARM_PAD```, ```SAT_UPLINK```, ```GATE``` and ```COMMAND_CONTROL```. diff --git a/src/quickjs_backend.cpp b/src/quickjs_backend.cpp index 4f08002cf3d..abf9a7ac419 100644 --- a/src/quickjs_backend.cpp +++ b/src/quickjs_backend.cpp @@ -794,6 +794,7 @@ JSValue convResearch(const RESEARCH *psResearch, JSContext *ctx, int player) //;; * ```status``` The completeness status of the structure. It will be one of ```BEING_BUILT``` and ```BUILT```. //;; * ```type``` The type will always be ```STRUCTURE```. //;; * ```cost``` What it would cost to build this structure. (3.2+ only) +//;; * ```direction``` The direction the structure is facing. (4.5+ only) //;; * ```stattype``` The stattype defines the type of structure. It will be one of ```HQ```, ```FACTORY```, ```POWER_GEN```, //;; ```RESOURCE_EXTRACTOR```, ```LASSAT```, ```DEFENSE```, ```WALL```, ```RESEARCH_LAB```, ```REPAIR_FACILITY```, //;; ```CYBORG_FACTORY```, ```VTOL_FACTORY```, ```REARM_PAD```, ```SAT_UPLINK```, ```GATE```, ```STRUCT_GENERIC```, and ```COMMAND_CONTROL```. @@ -835,6 +836,7 @@ JSValue convStructure(const STRUCTURE *psStruct, JSContext *ctx) QuickJS_DefinePropertyValue(ctx, value, "status", JS_NewInt32(ctx, (int)psStruct->status), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "health", JS_NewInt32(ctx, 100 * psStruct->body / MAX(1, psStruct->structureBody())), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "cost", JS_NewInt32(ctx, psStruct->pStructureType->powerToBuild), JS_PROP_ENUMERABLE); + QuickJS_DefinePropertyValue(ctx, value, "direction", JS_NewInt32(ctx, UNDEG(psStruct->rot.direction)), JS_PROP_ENUMERABLE); int stattype = 0; switch (psStruct->pStructureType->type) // don't bleed our source insanities into the scripting world {