adapt: adapt GMLIB v0.9.7

This commit is contained in:
Tsubasa6848
2024-03-23 19:11:00 +08:00
Unverified
parent 161123a670
commit a82a8cfb94
3 changed files with 57 additions and 8 deletions
+45 -1
View File
@@ -620,6 +620,49 @@ class Scoreboard {
}
class JsonConfig {
constructor(path, defultValue = {}) {
this.mData = defultValue;
this.mPath = path;
}
init() {
if (File.exists(this.mPath)) {
let existDataStr = File.readFrom(this.mPath);
this.mData = Object.assign({}, this.mData, JSON.parse(existDataStr));
}
this.save();
}
save(format = 4) {
let dataStr = JSON.stringify(this.mData, null, format);
File.writeTo(this.mPath, dataStr);
}
getData() {
return this.mData;
}
get(key, defultValue = null) {
let result = this.getData()[key];
if (!result && defultValue != null) {
this.set(key, defultValue);
return defultValue;
}
return result;
}
set(key, value) {
this.getData()[key] = value;
this.save();
}
delete(key) {
delete this.getData()[key];
this.save();
}
}
module.exports = {
StaticFloatingText,
DynamicFloatingText,
@@ -627,5 +670,6 @@ module.exports = {
Recipes,
Experiments,
GMLIB,
Scoreboard
Scoreboard,
JsonConfig
};