Skip to content

Adapt to BDS 1.21.80 #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions docs/apis/GuiAPI/FormBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ are called when there is player interaction, without fighting.

For a player object `pl`, using the function:

`pl.sendForm(fm,callback.forUpdating)`
`pl.sendForm(fm,callback[,forUpdating])`

- Parameters:
- fm : `SimpleForm`
Expand Down Expand Up @@ -176,7 +176,7 @@ For a specific form object `fm`, the following functions are available:

#### Add a Row of Input Boxes to the Form

`fm.addInput(title[,placeholder,default])`
`fm.addInput(title[,placeholder,default,tooltip])`

- Parameters:

Expand All @@ -185,25 +185,29 @@ For a specific form object `fm`, the following functions are available:
- placeholder : `String`
(Optional parameter) The default prompt in the input box.
- default : `String`
(Optional parameter) the default input in the input box.
(Optional parameter) The default input in the input box.
- tooltip : `String`
(Optional parameter, added in 0.12.0) The text of tooltip
- Return value: The processed form object (for other operations in the chain).
- Return value type: `CustomForm`

#### Add a Row of Switch Options to the Form

`fm.addSwitch(title[,default])`
`fm.addSwitch(title[,default,tooltip])`

- Parameters:
- title : `String`
Description text for a switch option.
- default : `Boolean`
(Optional parameter) Default state of the switch on/off.
- tooltip : `String`
(Optional parameter, added in 0.12.0) The text of tooltip
- Return value: The processed form object (for other operations in the chain).
- Return value type: `CustomForm`

#### Add a Drop-Down Menu to the Form

`fm.addDropdown(title,items[,default])`
`fm.addDropdown(title,items[,default,tooltip])`

- Parameters:

Expand All @@ -216,12 +220,15 @@ For a specific form object `fm`, the following functions are available:
- default : `Integer`
(Optional parameter) The number of the list item selected by default in the drop-down menu.
The sequence number starts from 0. The default is 0, that is, the first item in the list is selected by default.

- tooltip : `String`
(Optional parameter, added in 0.12.0) The text of tooltip
- Return value: The processed form object (for other operations in the chain).
- Return value type: `CustomForm`

#### Add a Row of Cursor Sliders to the Form

`fm.addSlider(title,min,max[,step,default])`
`fm.addSlider(title,min,max[,step,default,tooltip])`

- Parameters:
- title : `String`
Expand All @@ -236,12 +243,14 @@ For a specific form object `fm`, the following functions are available:
(Optional parameter) The default initial grid number of the cursor slider, the value must be between the minimum
and maximum grid number.
Defaults to 0, i.e. the slider is at the beginning of the slider row.
- tooltip : `String`
(Optional parameter, added in 0.12.0) The text of tooltip
- Return value: The processed form object (for other operations in the chain).
- Return value type: `CustomForm`

#### Add a Row of Step Sliders to the Form

`fm.addStepSlider(title,items[,default])`
`fm.addStepSlider(title,items[,default,tooltip])`

- Parameters:
- title : `String`
Expand All @@ -253,6 +262,9 @@ For a specific form object `fm`, the following functions are available:
- default : `Integer`
(Optional parameter) Default initial options for step slider. Serial numbers start from 0.
Defaults to 0, i.e. the slider is at the beginning of the slider row.

- tooltip : `String`
(Optional parameter, added in 0.12.0) The text of tooltip
- Return value: The processed form object (for other operations in the chain).
- Return value type: `CustomForm`

Expand Down
22 changes: 17 additions & 5 deletions docs/apis/GuiAPI/FormBuilder.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ reason可能会是`null`.

#### 向表单内增加一行输入框

`fm.addInput(title[,placeholder,default])`
`fm.addInput(title[,placeholder,default,tooltip])`

- 参数:

Expand All @@ -186,24 +186,28 @@ reason可能会是`null`.
(可选参数)输入框内的提示字符
- default : `String`
(可选参数)输入框中默认存在的内容
- tooltip : `String`
(可选参数,在0.12.0中加入)提示文本
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
- 返回值类型:`CustomForm`

#### 向表单内增加一行开关选项

`fm.addSwitch(title[,default])`
`fm.addSwitch(title[,default,tooltip])`

- 参数:
- title : `String`
开关选项描述文本
- default : `Boolean`
(可选参数)开关的默认状态 开 / 关
- tooltip : `String`
(可选参数,在0.12.0中加入)提示文本
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
- 返回值类型:`CustomForm`

#### 向表单内增加一行下拉菜单

`fm.addDropdown(title,items[,default])`
`fm.addDropdown(title,items[,default,tooltip])`

- 参数:

Expand All @@ -216,12 +220,15 @@ reason可能会是`null`.
- default : `Integer`
(可选参数)下拉菜单默认选中的列表项序号。
序号从0开始编号。默认为0,即默认选中列表的第一项

- tooltip : `String`
(可选参数,在0.12.0中加入)提示文本
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
- 返回值类型:`CustomForm`

#### 向表单内增加一行游标滑块

`fm.addSlider(title,min,max[,step,default])`
`fm.addSlider(title,min,max[,step,default,tooltip])`

- 参数:
- title : `String`
Expand All @@ -235,12 +242,14 @@ reason可能会是`null`.
- default : `Integer`
(可选参数)游标滑块默认初始格数,数值必须在最小和最大格数之间。
默认为0,即滑块位于滑块行的开头
- tooltip : `String`
(可选参数,在0.12.0中加入)提示文本
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
- 返回值类型:`CustomForm`

#### 向表单内增加一行步进滑块

`fm.addStepSlider(title,items[,default])`
`fm.addStepSlider(title,items[,default,tooltip])`

- 参数:
- title : `String`
Expand All @@ -252,6 +261,9 @@ reason可能会是`null`.
- default : `Integer`
(可选参数)步进滑块默认初始选项。序号从0开始编号
默认为0,即滑块位于滑块行的开头

- tooltip : `String`
(可选参数,在0.12.0中加入)提示文本
- 返回值:处理完毕的表单对象(便于连锁进行其他操作)
- 返回值类型:`CustomForm`

Expand Down
24 changes: 10 additions & 14 deletions src/legacy/api/DataAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,7 @@ Local<Value> MoneyClass::set(const Arguments& args) {
CHECK_ARG_TYPE(args[1], ValueKind::kNumber);

try {
return Boolean::newBoolean(
EconomySystem::setMoney(args[0].asString().toString(), args[1].asNumber().toInt64())
return Boolean::newBoolean(EconomySystem::setMoney(args[0].asString().toString(), args[1].asNumber().toInt64())
);
} catch (const std::invalid_argument& e) {
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneySet!");
Expand Down Expand Up @@ -570,8 +569,7 @@ Local<Value> MoneyClass::add(const Arguments& args) {
CHECK_ARG_TYPE(args[1], ValueKind::kNumber);

try {
return Boolean::newBoolean(
EconomySystem::addMoney(args[0].asString().toString(), args[1].asNumber().toInt64())
return Boolean::newBoolean(EconomySystem::addMoney(args[0].asString().toString(), args[1].asNumber().toInt64())
);
} catch (const std::invalid_argument& e) {
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneyAdd!");
Expand Down Expand Up @@ -615,14 +613,12 @@ Local<Value> MoneyClass::trans(const Arguments& args) {
try {
string note = "";
if (args.size() >= 4 && args[3].getKind() == ValueKind::kString) note = args[3].asString().toString();
return Boolean::newBoolean(
EconomySystem::transMoney(
args[0].asString().toString(),
args[1].asString().toString(),
args[2].asNumber().toInt64(),
note
)
);
return Boolean::newBoolean(EconomySystem::transMoney(
args[0].asString().toString(),
args[1].asString().toString(),
args[2].asNumber().toInt64(),
note
));
} catch (const std::invalid_argument& e) {
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error("Bad argument in MoneyTrans!");
ll::error_utils::printException(e, lse::LegacyScriptEngine::getInstance().getSelf().getLogger());
Expand Down Expand Up @@ -887,7 +883,7 @@ Local<Value> DataClass::toMD5(const Arguments& args) {
LOG_WRONG_ARG_TYPE(__FUNCTION__);
return Local<Value>();
}
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data));
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), data.size()));
}
CATCH("Fail in ToMD5!");
}
Expand All @@ -905,7 +901,7 @@ Local<Value> DataClass::toSHA1(const Arguments& args) {
LOG_WRONG_ARG_TYPE(__FUNCTION__);
return Local<Value>();
}
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data));
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), data.size()));
}
CATCH("Fail in ToSHA1!");
}
Expand Down
51 changes: 28 additions & 23 deletions src/legacy/api/GuiAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,26 @@ Local<Value> SimpleFormClass::addDivider(const Arguments& args) {

//////////////////// Custom Form ////////////////////

CustomFormClass::CustomFormClass() : ScriptClass(ScriptClass::ConstructFromCpp<CustomFormClass>{}), form("") {}
CustomFormClass::CustomFormClass() : ScriptClass(ScriptClass::ConstructFromCpp<CustomFormClass>{}), form() {}

// 生成函数
Local<Object> CustomFormClass::newForm() {
auto newp = new CustomFormClass();
return newp->getScriptObject();
}

lse::form::CustomFormWrapper* CustomFormClass::extract(Local<Value> v) {
lse::form::RawCustomForm* CustomFormClass::extract(Local<Value> v) {
if (EngineScope::currentEngine()->isInstanceOf<CustomFormClass>(v))
return EngineScope::currentEngine()->getNativeInstance<CustomFormClass>(v)->get();
else return nullptr;
}

// 成员函数
void CustomFormClass::sendForm(
lse::form::CustomFormWrapper* form,
Player* player,
script::Local<Function>& callback,
bool update
lse::form::RawCustomForm* form,
Player* player,
script::Local<Function>& callback,
bool update
) {
script::Global<Function> callbackFunc{callback};
auto cb = [engine{EngineScope::currentEngine()},
Expand All @@ -186,16 +186,18 @@ void CustomFormClass::sendForm(
EngineScope scope(engine);
Local<Value> result;
if (data) {
result = JsonToValue(*data);
auto dataJson = nlohmann::ordered_json::parse(*data);
result = JsonToValue(dataJson);
if (result.isNull()) result = Array::newArray();
}
auto reasonVal = reason.has_value() ? Number::newNumber((uchar)reason.value()) : Local<Value>();
try {
callback.get().call({}, PlayerClass::newPlayer(&player), result, reasonVal);
}
CATCH_IN_CALLBACK("sendForm")
};
if (update) form->sendUpdate(*player, std::move(cb));
else form->sendTo(*player, std::move(cb));
if (update) form->sendRawUpdate(*player, std::move(cb));
else form->sendRawTo(*player, std::move(cb));
}

Local<Value> CustomFormClass::setTitle(const Arguments& args) {
Expand Down Expand Up @@ -257,12 +259,14 @@ Local<Value> CustomFormClass::addInput(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kString)
if (args.size() >= 2) CHECK_ARG_TYPE(args[1], ValueKind::kString);
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kString);
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);

try {
std::string placeholder = args.size() >= 2 ? args[1].asString().toString() : "";
std::string def = args.size() >= 3 ? args[2].asString().toString() : "";
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";

form.appendInput(args[0].asString().toString(), placeholder, def);
form.appendInput("", args[0].asString().toString(), placeholder, def, tooltip);
return this->getScriptObject();
}
CATCH("Fail in addInput!")
Expand All @@ -277,12 +281,14 @@ Local<Value> CustomFormClass::addSwitch(const Arguments& args) {
return Local<Value>();
}
}
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kString);

try {
bool def =
args.size() >= 2 ? args[1].isBoolean() ? args[1].asBoolean().value() : args[1].asNumber().toInt32() : false;
std::string tooltip = args.size() >= 3 ? args[2].asString().toString() : "";

form.appendToggle(args[0].asString().toString(), def);
form.appendToggle("", args[0].asString().toString(), def, tooltip);
return this->getScriptObject();
}
CATCH("Fail in addSwitch!")
Expand All @@ -293,6 +299,7 @@ Local<Value> CustomFormClass::addDropdown(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kString)
CHECK_ARG_TYPE(args[1], ValueKind::kArray);
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);

try {
auto optionsArr = args[1].asArray();
Expand All @@ -302,9 +309,10 @@ Local<Value> CustomFormClass::addDropdown(const Arguments& args) {
options.emplace_back(optionsArr.get(i).asString().toString());
}

int def = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
int def = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";

form.appendDropdown(args[0].asString().toString(), options, def);
form.appendDropdown("", args[0].asString().toString(), options, def, tooltip);
return this->getScriptObject();
}
CATCH("Fail in addDropdown!")
Expand All @@ -317,6 +325,7 @@ Local<Value> CustomFormClass::addSlider(const Arguments& args) {
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kNumber);
if (args.size() >= 5) CHECK_ARG_TYPE(args[4], ValueKind::kNumber);
if (args.size() >= 6) CHECK_ARG_TYPE(args[5], ValueKind::kString);

try {
int minValue = args[1].asNumber().toInt32();
Expand All @@ -326,15 +335,9 @@ Local<Value> CustomFormClass::addSlider(const Arguments& args) {
int step = args.size() >= 4 ? args[3].asNumber().toInt32() : 1;
int defValue = args.size() >= 5 ? args[4].asNumber().toInt32() : minValue;
if (defValue < minValue || defValue > maxValue) defValue = minValue;
std::string tooltip = args.size() >= 6 ? args[5].asString().toString() : "";

form.appendSlider(

args[0].asString().toString(),
minValue,
maxValue,
step,
defValue
);
form.appendSlider("", args[0].asString().toString(), minValue, maxValue, step, defValue, tooltip);
return this->getScriptObject();
}
CATCH("Fail in addSlider!")
Expand All @@ -345,16 +348,18 @@ Local<Value> CustomFormClass::addStepSlider(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kString)
CHECK_ARG_TYPE(args[1], ValueKind::kArray);
if (args.size() >= 3) CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
if (args.size() >= 4) CHECK_ARG_TYPE(args[3], ValueKind::kString);

try {
auto stepsArr = args[1].asArray();
std::vector<std::string> steps;
steps.reserve(stepsArr.size());
for (size_t i = 0; i < stepsArr.size(); ++i) steps.push_back(stepsArr.get(i).asString().toString());

int defIndex = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
int defIndex = args.size() >= 3 ? args[2].asNumber().toInt32() : 0;
std::string tooltip = args.size() >= 4 ? args[3].asString().toString() : "";

form.appendStepSlider(args[0].asString().toString(), steps, defIndex);
form.appendStepSlider("", args[0].asString().toString(), steps, defIndex, tooltip);
return this->getScriptObject();
}
CATCH("Fail in addStepSlider!")
Expand Down
Loading
Loading