mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-09 20:47:00 -04:00
add "exists_as_package" script function
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
Function: exists_as_package
|
||||
|
||||
--Usage--
|
||||
> exists_as_package("package")
|
||||
|
||||
Check if a package exists in the data folder.
|
||||
|
||||
Returns the package's version number as major-minor-patch, or nil if the package does not exists.
|
||||
|
||||
--Parameters--
|
||||
! Parameter Type Description
|
||||
| @input@ [[type:string]] Full name of the package folder, including game and extension.
|
||||
|
||||
--Examples--
|
||||
> exists_as_package("magic-modules.mse-include") == "2026-02-28"
|
||||
> exists_as_package("magic-quadruple-faced-leveler.mse-style") == nil
|
||||
@@ -138,4 +138,5 @@ These functions are built into the program, other [[type:function]]s can be defi
|
||||
| [[fun:assert]] Check a condition for debugging purposes.
|
||||
| [[fun:warning]] Output a warning message.
|
||||
| [[fun:error]] Output an error message.
|
||||
| [[fun:exists_as_package]] Checks if a package exists.
|
||||
| [[fun:exists_in_package]] Checks if a file exists in a package.
|
||||
|
||||
@@ -90,6 +90,14 @@ SCRIPT_FUNCTION(error) {
|
||||
return script_nil;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(exists_as_package) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
Version version_out;
|
||||
bool result = package_manager.installedVersion(input, version_out);
|
||||
if (!result) return script_nil;
|
||||
SCRIPT_RETURN(version_out.toString());
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(exists_in_package) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
bool result = package_manager.existsInPackage(input);
|
||||
@@ -1018,6 +1026,7 @@ void init_script_basic_functions(Context& ctx) {
|
||||
ctx.setVariable(_("trace"), script_trace);
|
||||
ctx.setVariable(_("warning"), script_warning);
|
||||
ctx.setVariable(_("error"), script_error);
|
||||
ctx.setVariable(_("exists_as_package"), script_exists_as_package);
|
||||
ctx.setVariable(_("exists_in_package"), script_exists_in_package);
|
||||
// conversion
|
||||
ctx.setVariable(_("to_string"), script_to_string);
|
||||
|
||||
Reference in New Issue
Block a user