Skip to content

Commit

Permalink
add global variables library
Browse files Browse the repository at this point in the history
  • Loading branch information
MjnMixael committed Dec 18, 2024
1 parent 7f48375 commit 585815b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
72 changes: 72 additions & 0 deletions code/scripting/api/libs/globals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
//

#include "globalincs/version.h"

#include "globals.h"

#include "missionui/missionscreencommon.h"
#include "playerman/managepilot.h"

namespace scripting {

Check failure on line 11 in code/scripting/api/libs/globals.cpp

View workflow job for this annotation

GitHub Actions / Linux (Debug, clang-16)

clang-tidy: nested namespaces can be concatenated (modernize-concat-nested-namespaces)
namespace api {

//**********LIBRARY: Globals
ADE_LIB(l_GlobalVariables, "GlobalVariables", "gl", "Library of global values");

ADE_VIRTVAR(MAX_PILOTS,
l_GlobalVariables,
nullptr,
"Gets the maximum number of possible pilots.",
"number",
"The maximum number of pilots")
{
return ade_set_args(L, "i", MAX_PILOTS);
}

ADE_VIRTVAR(MAX_WING_SLOTS,
l_GlobalVariables,
nullptr,
"The maximum ships that can be in a loadout wing",
"number",
"A maximum number of ships")
{

return ade_set_args(L, "i", MAX_WING_SLOTS);
}

ADE_VIRTVAR(MAX_WING_BLOCKS,
l_GlobalVariables,
nullptr,
"The maximum wings that can be in a loadout",
"number",
"A maximum number of wings")
{

return ade_set_args(L, "i", MAX_WING_BLOCKS);
}

ADE_VIRTVAR(MAX_SHIP_PRIMARY_BANKS,
l_GlobalVariables,
nullptr,
"The maximum primary banks a ship can have",
"number",
"A maximum number of primary banks")
{

return ade_set_args(L, "i", MAX_SHIP_PRIMARY_BANKS);
}

ADE_VIRTVAR(MAX_SHIP_SECONDARY_BANKS,
l_GlobalVariables,
nullptr,
"The maximum secondary banks a ship can have",
"number",
"A maximum number of secondary banks")
{

return ade_set_args(L, "i", MAX_SHIP_SECONDARY_BANKS);
}

} // namespace api
} // namespace scripting
11 changes: 11 additions & 0 deletions code/scripting/api/libs/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "scripting/ade_api.h"

namespace scripting {

Check failure on line 5 in code/scripting/api/libs/globals.h

View workflow job for this annotation

GitHub Actions / Linux (Debug, clang-16)

clang-tidy: nested namespaces can be concatenated (modernize-concat-nested-namespaces)
namespace api {

DECLARE_ADE_LIB(l_GlobalVariables);

} // namespace api
} // namespace scripting
6 changes: 4 additions & 2 deletions code/scripting/api/libs/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ ADE_LIB_DERIV(l_UserInterface_PilotSelect, "PilotSelect", nullptr,
"API for accessing values specific to the Pilot Select UI.",
l_UserInterface);

ADE_VIRTVAR(MAX_PILOTS, l_UserInterface_PilotSelect, nullptr, "Gets the maximum number of possible pilots.", "number",
"The maximum number of pilots")
ADE_VIRTVAR_DEPRECATED(MAX_PILOTS, l_UserInterface_PilotSelect, nullptr, "Gets the maximum number of possible pilots.", "number",
"The maximum number of pilots",
gameversion::version(25, 0, 0, 0),
"This variable has moved to the GlobalVariabls library.")
{
return ade_set_args(L, "i", MAX_PILOTS);
}
Expand Down
1 change: 1 addition & 0 deletions code/scripting/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extern "C" {
#include "scripting/api/libs/cfile.h"
#include "scripting/api/libs/controls.h"
#include "scripting/api/libs/engine.h"
#include "scripting/api/libs/globals.h"
#include "scripting/api/libs/graphics.h"
#include "scripting/api/libs/hookvars.h"
#include "scripting/api/libs/hud.h"
Expand Down
2 changes: 2 additions & 0 deletions code/source_groups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,8 @@ add_file_folder("Scripting\\\\Api\\\\Libs"
scripting/api/libs/controls.h
scripting/api/libs/engine.cpp
scripting/api/libs/engine.h
scripting/api/libs/globals.cpp
scripting/api/libs/globals.h
scripting/api/libs/graphics.cpp
scripting/api/libs/graphics.h
scripting/api/libs/hookvars.cpp
Expand Down

0 comments on commit 585815b

Please sign in to comment.