From 8ab75344395e38e31e65464d594b23624ecea146 Mon Sep 17 00:00:00 2001 From: Ivan Mogilko Date: Mon, 4 Nov 2024 01:33:46 +0300 Subject: [PATCH] Script API: added Object.DestinationX/Y, complement Character's props --- Editor/AGS.Editor/Resources/agsdefns.sh | 10 +++++-- Engine/ac/object.cpp | 38 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Editor/AGS.Editor/Resources/agsdefns.sh b/Editor/AGS.Editor/Resources/agsdefns.sh index 72634086d6..992745199f 100644 --- a/Editor/AGS.Editor/Resources/agsdefns.sh +++ b/Editor/AGS.Editor/Resources/agsdefns.sh @@ -2641,6 +2641,12 @@ builtin managed struct Object { /// Gets the script name of this object. import readonly attribute String ScriptName; #endif // SCRIPT_API_v361 +#ifdef SCRIPT_API_v362 + /// Gets the X coordinate of the object's final moving destination; or current position if object is not moving. + readonly import attribute int DestinationX; + /// Gets the Y coordinate of the object's final moving destination; or current position if object is not moving. + readonly import attribute int DestinationY; +#endif int reserved[2]; // $AUTOCOMPLETEIGNORE$ }; @@ -2871,9 +2877,9 @@ builtin managed struct Character { import bool IsInteractionAvailable(CursorMode); /// Sets the individual light level for this character. import function SetLightLevel(int light_level); - /// Gets the X position this character is currently moving towards. + /// Gets the X coordinate of the character's final moving destination; or current position if character is not moving. readonly import attribute int DestinationX; - /// Gets the Y position this character is currently moving towards. + /// Gets the Y coordinate of the character's final moving destination; or current position if character is not moving. readonly import attribute int DestinationY; #endif // SCRIPT_API_v340 #ifdef SCRIPT_API_v341 diff --git a/Engine/ac/object.cpp b/Engine/ac/object.cpp index 28724de7a1..d4e3a6a729 100644 --- a/Engine/ac/object.cpp +++ b/Engine/ac/object.cpp @@ -335,6 +335,32 @@ int Object_GetClickable(ScriptObject *objj) { return 1; } +int Object_GetDestinationX(ScriptObject *objj) +{ + if (!is_valid_object(objj->id)) + quit("!Object.DestionationX: Invalid object specified"); + + if (objs[objj->id].moving) + { + MoveList *cmls = &mls[objs[objj->id].moving]; + return cmls->pos.back().X; + } + return objs[objj->id].x; +} + +int Object_GetDestinationY(ScriptObject *objj) +{ + if (!is_valid_object(objj->id)) + quit("!Object.DestionationX: Invalid object specified"); + + if (objs[objj->id].moving) + { + MoveList *cmls = &mls[objs[objj->id].moving]; + return cmls->pos.back().Y; + } + return objs[objj->id].y; +} + void Object_SetManualScaling(ScriptObject *objj, bool on) { if (on) objs[objj->id].flags &= ~OBJF_USEROOMSCALING; @@ -1031,6 +1057,16 @@ RuntimeScriptValue Sc_Object_SetClickable(void *self, const RuntimeScriptValue * API_OBJCALL_VOID_PINT(ScriptObject, Object_SetClickable); } +RuntimeScriptValue Sc_Object_GetDestinationX(void *self, const RuntimeScriptValue *params, int32_t param_count) +{ + API_OBJCALL_INT(ScriptObject, Object_GetDestinationX); +} + +RuntimeScriptValue Sc_Object_GetDestinationY(void *self, const RuntimeScriptValue *params, int32_t param_count) +{ + API_OBJCALL_INT(ScriptObject, Object_GetDestinationY); +} + // int (ScriptObject *objj) RuntimeScriptValue Sc_Object_GetFrame(void *self, const RuntimeScriptValue *params, int32_t param_count) { @@ -1230,6 +1266,8 @@ void RegisterObjectAPI() { "Object::set_BlockingWidth", API_FN_PAIR(Object_SetBlockingWidth) }, { "Object::get_Clickable", API_FN_PAIR(Object_GetClickable) }, { "Object::set_Clickable", API_FN_PAIR(Object_SetClickable) }, + { "Object::get_DestinationX", API_FN_PAIR(Object_GetDestinationX) }, + { "Object::get_DestinationY", API_FN_PAIR(Object_GetDestinationY) }, { "Object::get_Frame", API_FN_PAIR(Object_GetFrame) }, { "Object::get_Graphic", API_FN_PAIR(Object_GetGraphic) }, { "Object::set_Graphic", API_FN_PAIR(Object_SetGraphic) },