adapt: adapt GMLIB v0.9.7
This commit is contained in:
+45
-1
@@ -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
|
||||
};
|
||||
Reference in New Issue
Block a user