11#include "../settings_type.h"
17#include "../3rdparty/fmt/format.h"
19#include "../safeguards.h"
24 this->
engine->
ThrowError(fmt::format(
"your info.nut/library.nut doesn't have the method '{}'",
name));
41 static const char *
const required_functions[] = {
50 for (
const auto &required_function : required_functions) {
51 if (!info->
CheckMethod(required_function))
return SQ_ERROR;
90 int medium_value = INT32_MIN;
94 while (SQ_SUCCEEDED(sq_next(vm, -2))) {
95 const SQChar *key_string;
96 if (SQ_FAILED(sq_getstring(vm, -2, &key_string)))
return SQ_ERROR;
100 const SQChar *sqvalue;
101 if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue)))
return SQ_ERROR;
105 auto replace_with_underscore = [](
auto c) {
return c ==
'=' || c ==
','; };
107 std::replace_if(config.
name.begin(), config.
name.end(), replace_with_underscore,
'_');
109 }
else if (key ==
"description") {
110 const SQChar *sqdescription;
111 if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription)))
return SQ_ERROR;
114 }
else if (key ==
"min_value") {
116 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
117 config.
min_value = ClampTo<int32_t>(res);
119 }
else if (key ==
"max_value") {
121 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
122 config.
max_value = ClampTo<int32_t>(res);
124 }
else if (key ==
"easy_value") {
127 }
else if (key ==
"medium_value") {
129 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
130 medium_value = ClampTo<int32_t>(res);
132 }
else if (key ==
"hard_value") {
135 }
else if (key ==
"custom_value") {
137 }
else if (key ==
"default_value") {
139 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
142 }
else if (key ==
"random_deviation") {
144 }
else if (key ==
"step_size") {
146 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
147 config.
step_size = ClampTo<int32_t>(res);
148 }
else if (key ==
"flags") {
150 if (SQ_FAILED(sq_getinteger(vm, -1, &res)))
return SQ_ERROR;
154 this->
engine->
ThrowError(fmt::format(
"unknown setting property '{}'", key));
165 if ((items & 0x080) == 0) {
167 if ((items & 0x010) == 0 || (items & 0x020) == 0 || (items & 0x040) == 0) {
168 this->
engine->
ThrowError(
"please define all properties of a setting (min/max not allowed for booleans)");
176 items |= 0x010 | 0x020 | 0x040;
182 this->
engine->
ThrowError(
"please define all properties of a setting (min/max not allowed for booleans)");
192 const SQChar *setting_name_str;
193 if (SQ_FAILED(sq_getstring(vm, -2, &setting_name_str)))
return SQ_ERROR;
194 std::string setting_name =
StrMakeValid(setting_name_str);
198 if (item.name == setting_name) config = &item;
201 if (config ==
nullptr) {
202 this->
engine->
ThrowError(fmt::format(
"Trying to add labels for non-defined setting '{}'", setting_name));
205 if (!config->
labels.empty())
return SQ_ERROR;
209 while (SQ_SUCCEEDED(sq_next(vm, -2))) {
210 const SQChar *key_string;
212 if (SQ_FAILED(sq_getstring(vm, -2, &key_string)))
return SQ_ERROR;
213 if (SQ_FAILED(sq_getstring(vm, -1, &label)))
return SQ_ERROR;
218 if (*key_string ==
'_') {
223 int key = atoi(key_string) * sign;
233 if (config->
labels.find(value) == config->
labels.end()) {
250 if (item.name ==
name)
return &item;
258 if (item.name !=
name)
continue;
All static information from an Script like name, version, etc.
std::string short_name
Short name (4 chars) which uniquely identifies the script.
int version
Version of the script.
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
std::string description
Small description of the script.
ScriptConfigItemList config_list
List of settings from this Script.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
bool CheckMethod(const char *name) const
Check if a given method exists.
class Squirrel * engine
Engine used to register for Squirrel.
std::string name
Full name of the script.
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
std::string main_script
The full path of the script.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
std::string instance_name
Name of the main class in the script.
bool GetSettings()
Get the settings of the Script.
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
std::string author
Author of the script.
int GetSettingDefaultValue(const std::string &name) const
Get the default value for a setting.
std::string tar_file
If, which tar file the script was in.
const ScriptConfigItem * GetConfigItem(const std::string_view name) const
Get the description of a certain Script config option.
std::string url
URL of the script.
std::string date
The date the script was written at.
Scanner to help finding scripts.
std::string GetTarFile()
Get the current tar file the ScanDir is currently tracking.
class Squirrel * GetEngine()
Get the engine of the main squirrel handler (it indexes all available scripts).
std::string GetMainScript()
Get the current main script the ScanDir is currently tracking.
static void * GetGlobalPointer(HSQUIRRELVM vm)
Get the pointer as set by SetGlobalPointer.
void ThrowError(const std::string_view error)
Throw a Squirrel error that will be nicely displayed to the user.
static bool GetInstance(HSQUIRRELVM vm, HSQOBJECT *ptr, int pos=1)
Get the Squirrel-instance pointer.
bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
Call a method of an instance, in various flavors.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
ScriptConfigFlags
Bitmask of flags for Script settings.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
ScriptInfo keeps track of all information of a script, like Author, Description, ....
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
static const int MAX_GET_SETTING_OPS
Maximum number of operations allowed for getting a particular setting.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Declarations of the class for the script scanner.
declarations and parts of the implementation of the class for convert code
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
LabelMapping labels
Text labels for the integer values.
std::string name
The name of the configuration setting.
int default_value
The default value of this configuration setting.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
int step_size
The step size in the gui.
std::string description
The description of the configuration setting.
bool complete_labels
True if all values have a label.