Skip to content

Commit 52c8832

Browse files
committed
publish YACGM
1 parent 13029af commit 52c8832

22 files changed

+1002
-5
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"import/extensions": "off",
2323
"no-shadow": "off",
2424
"@typescript-eslint/no-shadow": "error",
25-
"no-restricted-syntax":"off"
25+
"no-restricted-syntax": "off",
26+
"no-param-reassign": "off",
27+
"no-bitwise": "off"
2628
},
2729
"settings": {
2830
"import/resolver": {

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
**/node_modules/**
2-
**/dist/**
1+
node_modules/
2+
dist/
33
/index.js
4-
/package-lock.json
4+
package-lock.json
55
# /package.json
6-
.vscode/**
6+
.vscode/
77
/private/
8+
test.*

YetAnotherCustomGetMap/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "yet-another-custom-get-map",
3+
"version": "0.1.0",
4+
"description": "Yet another LLSE CustomGetMap plugin.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "rollup -c ./rollup.config.mjs",
9+
"watch": "rollup -c ./rollup.config.mjs --watch"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/lgc2333/LLSEPlugins.git"
14+
},
15+
"author": "student_2333 <[email protected]>",
16+
"license": "Apache-2.0",
17+
"bugs": {
18+
"url": "https://github.com/lgc2333/LLSEPlugins/issues"
19+
},
20+
"homepage": "https://github.com/lgc2333/LLSEPlugins#readme",
21+
"devDependencies": {
22+
"@rollup/plugin-json": "^5.0.1",
23+
"@rollup/plugin-terser": "^0.1.0",
24+
"@rollup/plugin-typescript": "^9.0.2",
25+
"@types/rimraf": "^3.0.2",
26+
"@types/sharp": "^0.31.0",
27+
"rollup": "^3.4.0"
28+
},
29+
"dependencies": {
30+
"jimp": "^0.16.2"
31+
}
32+
}

YetAnotherCustomGetMap/readme.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!-- markdownlint-disable MD033 -->
2+
3+
# YetAnotherCustomGetMap
4+
5+
另一个更易用的 [CustomMap](https://github.com/yhzx233/CustomMap) 辅助插件!
6+
下载本插件请去 [Releases](https://github.com/lgc2333/LLSEPlugins/releases)
7+
8+
本插件前置:[CustomMap](https://github.com/yhzx233/CustomMap)
9+
10+
## 介绍
11+
12+
插件使用 [Jimp](https://github.com/oliver-moran/jimp) 库来处理图片以及生成地图画二进制文件,**不需要借助其他程序**
13+
但缺点是**处理图片的时候会卡服**
14+
(性能更好的 [sharp](https://github.com/lovell/sharp) 库会崩服 悲)
15+
16+
插件支持的图片格式:bmp、gif、jpeg、png、tiff,**不支持** webp
17+
18+
直接上截图,顺便介绍一下插件
19+
20+
## 截图
21+
22+
**插件指令**
23+
YetAnotherCustomGetMap -> YACGM,你也可以在配置文件中更改命令名称
24+
![1](readme/Screenshot_20221123-043648.png)
25+
26+
**图片列表**
27+
![2](readme/Screenshot_20221123-043714.png)
28+
29+
**选择文件后图片处理方式选择表单**
30+
可选 宽高、处理方式(裁剪/拉伸/保留白边)、处理后水平垂直位置、缩放图片使用的插值法(最近邻/双线性/双三次/埃尔米特/贝塞尔)
31+
![3](readme/Screenshot_20221123-043823.png)
32+
![4](readme/Screenshot_20221123-043828.png)
33+
34+
**获取地图演示**
35+
受到 [CustomGetMap](https://www.minebbs.com/resources/customgetmap-custommap.4050/) 插件的启发(因为那个插件一次给全部地图很蛋疼),我把插件的给地图逻辑设计成了当空出主手时才会按顺序给一张,还加上了当前已给予的地图信息的提示,这样当拼一些大地图的时候就不会那么蛋疼了
36+
如果你搞乱了顺序,可以随时使用 `yacgm jump <地图序号>` 跳转到某一张地图
37+
![5](readme/Screenshot_20221123-043901.png)
38+
![6](readme/Screenshot_20221123-044107.png)
39+
![7](readme/Screenshot_20221123-044339.png)
40+
![8](readme/Screenshot_20221123-044247.png)
41+
42+
## 使用
43+
44+
1. 先去 [Releases](https://github.com/lgc2333/LLSEPlugins/releases) 下载本插件,放在插件文件夹下,开服
45+
2. 插件加载成功后会在插件文件夹内生成 `YetAnotherCustomGetMap/img` 文件夹,把图片文件放进里面就可以在插件菜单里看到了
46+
47+
## 指令
48+
49+
### `yacgm`(这个指令可以在配置文件中修改)
50+
51+
- 不带任何参数 - 打开插件主界面
52+
- `get <fileName:string>` - 直接选择指定的文件,弹出图片处理表单
53+
- `fileName` - 图片文件名,需要带后缀,文件需要在插件的图片文件夹中
54+
- `jump <jumpIndex:int>` - 在获取地图的过程中,直接跳转到指定序号的地图
55+
- `jumpIndex` - 要跳转到的地图序号(序号从 1 开始)
56+
- `stop` - 在获取地图的过程中,停止获取地图
57+
- `reload` - 重载插件配置(必须 OP 才能执行)
58+
59+
## 配置文件
60+
61+
配置文件路径:`plugins/YetAnotherCustomGetMap/config.json`
62+
请按照下面的注释修改配置文件
63+
注意:实际配置文件里**不能有注释**
64+
65+
```jsonc
66+
{
67+
// 插件指令名称,修改后需要重启服务器
68+
"mainCommand": "yacgm",
69+
70+
// 是否只有OP才能使用插件指令
71+
// 此配置不对 `yacgm reload` 指令生效
72+
"onlyOP": true,
73+
74+
// 插件菜单每页展示的文件数量
75+
"pageLimit": 15
76+
}
77+
```
78+
79+
## 联系我
80+
81+
QQ:3076823485
82+
吹水群:[1105946125](https://jq.qq.com/?_wv=1027&k=Z3n1MpEp)
83+
84+
85+
## 赞助
86+
87+
感谢大家的赞助!你们的赞助将是我继续创作的动力!
88+
89+
- [爱发电](https://afdian.net/@lgc2333)
90+
- <details>
91+
<summary>赞助二维码(点击展开)</summary>
92+
93+
![讨饭](https://raw.githubusercontent.com/lgc2333/ShigureBotMenu/master/src/imgs/sponsor.png)
94+
95+
</details>
96+
97+
## 更新日志
98+
99+
暂无
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import typescript from '@rollup/plugin-typescript';
3+
import json from '@rollup/plugin-json';
4+
// import resolve from '@rollup/plugin-node-resolve';
5+
// import cjs from '@rollup/plugin-commonjs';
6+
import terser from '@rollup/plugin-terser';
7+
8+
export default {
9+
input: 'src/index.ts',
10+
output: {
11+
file: 'dist/index.js',
12+
format: 'cjs',
13+
inlineDynamicImports: true,
14+
},
15+
plugins: [json(), typescript(), terser()],
16+
};

YetAnotherCustomGetMap/src/command.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { config, reloadConfig } from './config';
2+
import { pluginName } from './const';
3+
import { formFiles, formGet } from './form';
4+
import { mapGetControls } from './give-map';
5+
import { callAsyncLogErr, formatError } from './util';
6+
7+
interface CmdGetMapCallback {
8+
enumGet?: 'get';
9+
fileName?: string;
10+
// enumNext?: 'next';
11+
// enumPrevious?: 'previous';
12+
enumJump?: 'jump';
13+
jumpIndex?: number;
14+
enumStop?: 'stop';
15+
enumReload?: 'reload';
16+
}
17+
18+
const cmdGetMap = mc.newCommand(config.mainCommand, pluginName, PermType.Any);
19+
20+
cmdGetMap.setEnum('enumGet', ['get']);
21+
// cmdGetMap.setEnum('enumNext', ['next']);
22+
// cmdGetMap.setEnum('enumPrevious', ['previous']);
23+
cmdGetMap.setEnum('enumJump', ['jump']);
24+
cmdGetMap.setEnum('enumStop', ['stop']);
25+
cmdGetMap.setEnum('enumReload', ['reload']);
26+
27+
cmdGetMap.mandatory('fileName', ParamType.String);
28+
cmdGetMap.mandatory('enumGet', ParamType.Enum, 'enumGet', 1);
29+
// cmdGetMap.mandatory('enumNext', ParamType.Enum, 'enumNext', 1);
30+
// cmdGetMap.mandatory('enumPrevious', ParamType.Enum, 'enumPrevious', 1);
31+
cmdGetMap.mandatory('enumJump', ParamType.Enum, 'enumJump', 1);
32+
cmdGetMap.mandatory('jumpIndex', ParamType.Int);
33+
cmdGetMap.mandatory('enumStop', ParamType.Enum, 'enumStop', 1);
34+
cmdGetMap.mandatory('enumReload', ParamType.Enum, 'enumReload', 1);
35+
36+
cmdGetMap.overload([]);
37+
cmdGetMap.overload(['enumGet', 'fileName']);
38+
// cmdGetMap.overload(['enumNext']);
39+
// cmdGetMap.overload(['enumPrevious']);
40+
cmdGetMap.overload(['enumJump', 'jumpIndex']);
41+
cmdGetMap.overload(['enumStop']);
42+
cmdGetMap.overload(['enumReload']);
43+
44+
cmdGetMap.setCallback((_, origin, out, res: CmdGetMapCallback) => {
45+
const {
46+
enumGet,
47+
fileName,
48+
// enumNext,
49+
// enumPrevious,
50+
enumJump,
51+
jumpIndex,
52+
enumStop,
53+
enumReload,
54+
} = res;
55+
const { player } = origin;
56+
57+
// reload指令仅OP可用
58+
if ((config.onlyOP || enumReload) && player && player.permLevel < 1) {
59+
out.error('此命令仅OP可用');
60+
return;
61+
}
62+
63+
if (player && !enumReload) {
64+
// 有玩家 非reload指令
65+
if (/* enumNext || enumPrevious || */ enumJump || enumStop) {
66+
// jump和stop指令
67+
const ctrl = mapGetControls[player.xuid];
68+
if (!ctrl) {
69+
out.error('目前没有正在进行中的给予任务');
70+
return;
71+
}
72+
73+
const { /* addMapIndex, */ stopGive, jumpMapIndex } = ctrl;
74+
if (enumStop) {
75+
stopGive(player);
76+
}
77+
// else if (enumNext || enumPrevious) {
78+
// addMapIndex(player, !!enumNext);
79+
// }
80+
else if (enumJump) {
81+
jumpMapIndex(player, (jumpIndex as number) - 1); // 从0开始
82+
}
83+
}
84+
// 下面是get和主指令
85+
else if (Object.keys(mapGetControls).includes(player.xuid)) {
86+
// 如果存在玩家的控制地图给予函数(有地图给予进程运行中)
87+
out.error('已有获取地图任务运行中,请先停止');
88+
} else if (enumGet) {
89+
// 指令 get <文件名> 直接调用图片处理函数
90+
if (fileName) callAsyncLogErr(formGet)(player, fileName);
91+
} else {
92+
// 无参数,调用主表单
93+
callAsyncLogErr(formFiles)(player);
94+
}
95+
} else if (enumReload) {
96+
// 重载配置(无论调用者是不是玩家)
97+
try {
98+
reloadConfig();
99+
} catch (e) {
100+
out.error(`重载配置失败!\n${formatError(e)}`);
101+
return;
102+
}
103+
out.success('重载配置成功!更改指令名称后重启服务器才能生效!');
104+
} else {
105+
// 没有玩家 也不是重载配置
106+
out.error('此命令仅限玩家执行');
107+
}
108+
});
109+
cmdGetMap.setup();

YetAnotherCustomGetMap/src/config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { existsSync, readFileSync, writeFileSync } from 'fs';
2+
import { join } from 'path';
3+
4+
import { dataPath } from './const';
5+
6+
const configPath = join(dataPath, 'config.json');
7+
8+
interface Config {
9+
/** 插件指令名 */
10+
mainCommand: string;
11+
/** 是否只有OP才能使用插件指令(reload除外) */
12+
onlyOP: boolean;
13+
/** 图片列表每页文件数 */
14+
pageLimit: number;
15+
}
16+
17+
export const config: Config = {
18+
mainCommand: 'yacgm',
19+
onlyOP: true,
20+
pageLimit: 15,
21+
};
22+
23+
/**
24+
* 同步保存配置
25+
*/
26+
export function saveConfig() {
27+
writeFileSync(configPath, JSON.stringify(config, null, 2));
28+
}
29+
30+
/**
31+
* 同步重载配置文件
32+
*/
33+
export function reloadConfig() {
34+
if (!existsSync(configPath)) saveConfig();
35+
else
36+
Object.entries(
37+
JSON.parse(readFileSync(configPath, { encoding: 'utf-8' })) as Config
38+
).forEach((x) => {
39+
const [k, v] = x;
40+
Object.defineProperty(config, k, { value: v });
41+
});
42+
}
43+
44+
reloadConfig();

YetAnotherCustomGetMap/src/const.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { existsSync, mkdirSync } from 'fs';
2+
import { join } from 'path';
3+
4+
import { description, version } from '../package.json';
5+
6+
export const pluginName = 'YetAnotherCustomGetMap';
7+
export const pluginVersion = version.split('.').map((v) => Number(v));
8+
export const pluginDescription = description;
9+
export const pluginExtra = {
10+
Author: 'student_2333',
11+
License: 'Apache-2.0',
12+
};
13+
14+
/** 插件数据文件夹 */
15+
export const dataPath = join('./plugins', pluginName);
16+
/** 用户存放图片文件夹 */
17+
export const imgPath = join(dataPath, 'img');
18+
/** 生成后的二进制文件临时存放文件夹 */
19+
export const tmpPath = join(dataPath, 'tmp');
20+
// 创建文件夹(临时文件夹在index.ts里清理并重新创建了)
21+
[dataPath, imgPath /* , tmpPath */].forEach((p) => {
22+
if (!existsSync(p)) mkdirSync(p);
23+
});
24+
25+
/** 地图画宽高 */
26+
export const cutSize = 128;

0 commit comments

Comments
 (0)