From e08e5d99eb4f21b0030f4d6a13139eae0fa6fa7a Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Mon, 13 May 2024 21:15:58 +0800 Subject: [PATCH] refactor: rewrite experiments shit --- lib/GMLIB_API-JS.js | 16 +++------------- src/CompatibilityApi.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index ab9a068..e2a3365 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -33,7 +33,7 @@ const GMLIB_API = { PlayerToEntity: ll.import("GMLib_ServerAPI", "PlayerToEntity"), setUnknownBlockCleaner: ll.import("GMLib_ModAPI", "setUnknownBlockCleaner"), getAllExperiments: ll.import("GMLIB_API", "getAllExperiments"), - getExperimentTranslatedName: ll.import("GMLIB_API", "getExperimentTranslatedName"), + getExperimentTranslateKey: ll.import("GMLIB_API", "getExperimentTranslateKey"), getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"), setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"), unregisterRecipe: ll.import("GMLIB_API", "unregisterRecipe"), @@ -432,18 +432,8 @@ class Experiments { return GMLIB_API.getAllExperiments(); } - static getExperimentTranslatedName(id) { - return GMLIB_API.getExperimentTranslatedName(id); - } - - static getExperimentsMap() { - let ids = this.getAllExperimentIds(); - let result = {}; - for (let id in ids) { - let name = this.getExperimentTranslatedName(id); - result[id] = name; - } - return result; + static getExperimentTranslateKey(id) { + return GMLIB_API.getExperimentTranslateKey(id); } static getExperimentEnabled(id) { diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 14bb233..8f1b05c 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -77,12 +77,12 @@ void Export_Compatibility_API() { } return result; }); - RemoteCall::exportAs("GMLIB_API", "getExperimentTranslatedName", [](int id) -> std::string { - auto map = GMLIB_Level::getAllExperimentsTranslateKeys(); - if (map.count(id)) { - return std::string(map[id]); - } - return ""; + RemoteCall::exportAs("GMLIB_API", "getExperimentTranslateKey", [](int id) -> std::string { + std::string result; + try { + result = Experiments::getExperimentTextID(AllExperiments(id)); + } catch (...) {} + return result; }); RemoteCall::exportAs( "GMLIB_API",