mirror of
https://github.com/tuanzisama/minecraft-color-gradient-generator.git
synced 2024-11-27 02:30:55 +08:00
feat: support Chat Colors
Ref: https://www.curseforge.com/minecraft/mc-mods/chat-colours
This commit is contained in:
parent
5a0aa9694d
commit
2cfacd4a70
35
src/plugins/processor/adapter/chat-colors.ts
Normal file
35
src/plugins/processor/adapter/chat-colors.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { CharacterBuilder, TextBuilder } from "../builder/text";
|
||||
import { GradientProcessor, GradientProcessorConstructor } from "../processor-core";
|
||||
|
||||
class ChatColorsAdapterClazz extends GradientProcessor {
|
||||
constructor(tags: RichTagChunk, colors: HexColorString[], options?: GradientProcessAdapterOptions) {
|
||||
super(tags, colors, options);
|
||||
}
|
||||
|
||||
override get format(): FormatPresets {
|
||||
return {
|
||||
bold: ["**", "**"],
|
||||
italic: ["*", "*"],
|
||||
underlined: ["__", "__"],
|
||||
strikethrough: ["~~", "~~"],
|
||||
obfuscated: "",
|
||||
reset: "",
|
||||
};
|
||||
}
|
||||
|
||||
processor(chunk: Chunk): string {
|
||||
const textBuilder = new TextBuilder();
|
||||
textBuilder.withFormat(chunk.format?.bold, this.format.bold);
|
||||
textBuilder.withFormat(chunk.format?.italic, this.format.italic);
|
||||
textBuilder.withFormat(chunk.format?.underlined, this.format.underlined);
|
||||
textBuilder.withFormat(chunk.format?.strikethrough, this.format.strikethrough);
|
||||
|
||||
chunk.tags.forEach((tag) => {
|
||||
textBuilder.appendCharacter(new CharacterBuilder(tag.character).withColor(tag.color, "[{color}]"));
|
||||
});
|
||||
|
||||
return textBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
export const ChatColorsAdapter: GradientProcessorConstructor = ChatColorsAdapterClazz;
|
@ -13,6 +13,7 @@ import { MotdAdapter } from "./adapter/motd";
|
||||
import { BBCodeAdapter } from "./adapter/bbcode";
|
||||
import { HTMLAdapter } from "./adapter/html";
|
||||
import { CSVAdapter } from "./adapter/csv";
|
||||
import { ChatColorsAdapter } from "./adapter/chat-colors";
|
||||
|
||||
interface AdapterMapValue<T = any> {
|
||||
label: `processor.adapter.${string}.label`;
|
||||
@ -43,6 +44,7 @@ export const adapterMap = new Map<KeyOfAdapterMap, AdapterMapValue>([
|
||||
},
|
||||
],
|
||||
["trchat", { label: "processor.adapter.trchat.label", sample: "&{#RRGGBB}", adapter: TrChatAdapter }],
|
||||
["chat-colors", { label: "processor.adapter.chat_colors.label", sample: "[#RRGGBB]", adapter: ChatColorsAdapter }],
|
||||
["motd", { label: "processor.adapter.motd.label", sample: "\\u00A7X", adapter: MotdAdapter }],
|
||||
["bbcode", { label: "processor.adapter.bbcode.label", sample: "[color=#RRGGBB]", adapter: BBCodeAdapter }],
|
||||
[
|
||||
@ -68,6 +70,7 @@ export const adapterMapKey = [
|
||||
"minedown",
|
||||
"stringified-nbt",
|
||||
"trchat",
|
||||
"chat-colors",
|
||||
"motd",
|
||||
"bbcode",
|
||||
"json",
|
||||
|
@ -122,6 +122,9 @@ export default {
|
||||
trchat: {
|
||||
label: "TrChat",
|
||||
},
|
||||
chat_colors: {
|
||||
label: "Chat Colors",
|
||||
},
|
||||
motd: {
|
||||
label: "MOTD",
|
||||
},
|
||||
|
@ -124,6 +124,9 @@ export default {
|
||||
trchat: {
|
||||
label: "TrChat",
|
||||
},
|
||||
chat_colors: {
|
||||
label: "Chat Colors",
|
||||
},
|
||||
motd: {
|
||||
label: "MOTD",
|
||||
},
|
||||
|
@ -119,6 +119,9 @@ export default {
|
||||
trchat: {
|
||||
label: "TrChat",
|
||||
},
|
||||
chat_colors: {
|
||||
label: "Chat Colors",
|
||||
},
|
||||
motd: {
|
||||
label: "MOTD",
|
||||
},
|
||||
|
@ -118,6 +118,9 @@ export default {
|
||||
trchat: {
|
||||
label: "TrChat",
|
||||
},
|
||||
chat_colors: {
|
||||
label: "Chat Colors",
|
||||
},
|
||||
motd: {
|
||||
label: "MOTD",
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user