mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 08:15:59 -10:00
* Automatically generate the isValid() Lua API function for handle types If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically. An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own. The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one. Co-Authored-By: Claude Fable 5.1 <[email protected]> * Add ADE_OBJ_VALIDATOR for index-based Lua handles Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ. The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles. The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid(). Add a validator to HudGauge while we're at it. Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
|
|
#include "comm_order.h"
|
|
#include "hud/hudsquadmsg.h"
|
|
|
|
namespace scripting::api {
|
|
|
|
//**********HANDLE: mission goals
|
|
ADE_OBJ_NO_MULTI(l_Comm_Item, int, "comm_item", "Comm Item handle");
|
|
ADE_OBJ_VALIDATOR(l_Comm_Item, idx, MsgItems.in_bounds(idx));
|
|
|
|
ADE_VIRTVAR(Name, l_Comm_Item, nullptr, "The name of the comm item", "string", "The comm item name")
|
|
{
|
|
int current;
|
|
if (!ade_get_args(L, "o", l_Comm_Item.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
SCP_string message = "Invalid comm item!";
|
|
if (MsgItems.in_bounds(current)) {
|
|
message = MsgItems[current].text;
|
|
}
|
|
return ade_set_args(L, "s", message.c_str());
|
|
}
|
|
|
|
ADE_VIRTVAR(Active, l_Comm_Item, nullptr, "Whether or not the item is active", "boolean", "The active status")
|
|
{
|
|
int current;
|
|
if (!ade_get_args(L, "o", l_Comm_Item.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
if (MsgItems.in_bounds(current) && MsgItems[current].active > 0) {
|
|
return ADE_RETURN_TRUE;
|
|
}
|
|
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
// Yes, it's a little silly to get this this way. Adding a getter to the mission library was an option but for that I'd
|
|
// have to be sure the title is always set which is fine but mostly it just felt out of place. Having this here keeps all
|
|
// comm menu code neat and tidy right here. I also thought about adding it as a parameter of the On HUD Comm Menu Open hook
|
|
// but that method wouldn't update as the player moves through the menu since the hook only runs once.
|
|
ADE_FUNC(getMenuTitle, l_Comm_Item, nullptr, "Gets the current title of the menu. Will be the same for all currently valid comm items.", "string", "The menu title")
|
|
{
|
|
int current = -1;
|
|
|
|
if (!ade_get_args(L, "o", l_Comm_Item.Get(¤t)))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
return ade_set_args(L, "s", Squad_msg_title);
|
|
}
|
|
|
|
ADE_FUNC(selectItem, l_Comm_Item, nullptr, "Selects the item and either proceeds to the next menu or issues the order", "boolean", "Returns true if successful, false otherwise")
|
|
{
|
|
int current = -1;
|
|
|
|
if (!ade_get_args(L, "o", l_Comm_Item.Get(¤t)))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
if (!MsgItems.in_bounds(current)) {
|
|
LuaError(L, "Lua tried to select squad message that is not valid!");
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
Hud_set_lua_key(current);
|
|
|
|
return ADE_RETURN_TRUE;
|
|
}
|
|
|
|
} // namespace scripting::api
|