adapt: adapt gmlib 1.0.0-rc.2 and levilamina 1.1.0

This commit is contained in:
zimuya4153
2025-03-22 00:10:55 +08:00
Unverified
parent b34c84f157
commit accf1d0664
15 changed files with 883 additions and 621 deletions
+3 -3
View File
@@ -12,7 +12,7 @@ export class PAPI {
pluginsName: string,
/** PAPI变量 */
PAPIName: string
): boolean;
): void;
/** 注册一个服务器PAPI变量 */
static registerServerPlaceholder(
@@ -25,7 +25,7 @@ export class PAPI {
pluginsName: string,
/** PAPI变量 */
PAPIName: string
): boolean;
): void;
/** 注册一个静态PAPI变量 */
static registerStaticPlaceholder(
@@ -37,7 +37,7 @@ export class PAPI {
PAPIName: string,
/** 更新时间 */
UpdateInterval: number
): boolean;
): void;
/** 获取一个服务器变量的值 */
static getValue(
+3 -3
View File
@@ -59,7 +59,7 @@ class PAPI {
*/
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
}
/**
@@ -71,7 +71,7 @@ class PAPI {
*/
static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
}
/**
@@ -84,7 +84,7 @@ class PAPI {
*/
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
ll.export(func, PluginName, func.getName());
return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
}
/**
+3 -1
View File
@@ -5,7 +5,9 @@ const getPluginName = () => {
try {
throw new Error("getPluginName");
} catch (error) {
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1] || "Unknown";
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1]
|| error.stack.trim().match(/at <anonymous> \(([^\\|/]+)(.*?):\d+:\d+\)$/i)?.[1]
|| "Unknown";
}
};
+42
View File
@@ -0,0 +1,42 @@
/** 翻译带PAPI变量文本 */
export function translate(
/** 要翻译的文本 */
value: String,
/** 实体对象 */
actor?: Entity,
/** 目标翻译语言 */
language?: String
): String;
/** 注册PAPI变量 */
export function registerPlaceholder(
/** papi变量 */
placeholder: String,
/** 回调 */
callback: (
/** 实体对象 */ actor: Entity,
/** 参数 */ params: String[],
/** 目标翻译语言 */language: String
) => String | undefined
): void;
/** 注销PAPI变量 */
export function unregisterPlaceholder(
/** papi变量 */
placeholder: String
): Boolean;
/** 根据模组名注销PAPI变量 */
export function unregisterPlaceholderFromModName(
/** 模组名 */
modName: String
): Boolean;
/** 获取一个papi变量的值 */
export function getValue(
/** papi变量名 */
placeholder: String,
actor?: Entity,
params?: Record<String, String>,
language?: string
): Boolean;
+65
View File
@@ -0,0 +1,65 @@
/// <reference path='d:/dts/dts/helperlib/src/index.d.ts'/>
const getPluginName = () => {
try {
throw new Error("getPluginName");
} catch (error) {
return error.stack.trim().match(/plugins\\(.*)\\.*\.js:[0-9]+\)$/i)?.[1]
|| error.stack.trim().match(/at <anonymous> \(([^\\|/]+)(.*?):\d+:\d+\)$/i)?.[1]
|| "Unknown";
}
};
Function.prototype.getName =
/**
* 获取函数名字
* @returns {string}
*/
function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)?.[1] || getStringHashCode(this.toString()).toString(16);
};
/**
* 获取字符串哈希值
* @param {string} str 字符串
* @returns {number}
*/
function getStringHashCode(str) {
let hash = 0, chr;
if (str.length === 0) return hash;
for (let i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return hash;
}
module.exports = {
translate(value, actor = undefined, language = "") {
return actor instanceof LLSE_Entity
? ll.imports("PlaceholderAPI", "translateFromActor")(value, actor, language)
: ll.imports("PlaceholderAPI", "translate")(value, language);
},
registerPlaceholder(placeholder, callback) {
const pluginName = getPluginName();
ll.exports((...args) => {
if(!args[0].uniqueId) args[0] = undefined;
return callback(...args) ?? "<std::nullopt>";
}, pluginName, callback.getName());
ll.imports("PlaceholderAPI", "registerPlaceholder")(placeholder, callback.getName(), pluginName);
},
unregisterPlaceholder(placeholder) {
return ll.imports("PlaceholderAPI", "unregisterPlaceholder")(placeholder);
},
unregisterPlaceholderFromModName(placeholder) {
return ll.imports("PlaceholderAPI", "unregisterPlaceholderFromModName")(placeholder);
},
getValue(placeholder, actor = undefined, params = {}, language = "") {
if (actor instanceof LLSE_Player) actor = ll.import("GMLib_ServerAPI", "PlayerToEntity")(actor);
const result = actor instanceof LLSE_Entity
? ll.imports("PlaceholderAPI", "getValueFromActor")(placeholder, actor, params, language)
: ll.imports("PlaceholderAPI", "getValue")(placeholder, params, language);
return result !== "<std::nullopt>" ? result : undefined;
}
};