add: blend.json support.

master
WildEgo 2025-06-25 18:55:51 +01:00
parent 320cb7342c
commit 76e7d92eee
4 changed files with 110 additions and 4 deletions

View File

@ -24,9 +24,16 @@ const fileType = await select({
value: 'special_item_group',
label: 'special_item_group.txt',
},
{
value: 'blend',
label: 'blend.txt',
},
],
});
const getProto = () =>
csvToJson.fieldDelimiter('\t').csvStringToJson(itemProto);
if (isCancel(fileType)) {
cancel('Operation cancelled');
process.exit(0);
@ -36,9 +43,9 @@ await match(fileType)
.with('special_item_group', async () => {
const s = spinner();
const proto = csvToJson.fieldDelimiter('\t').csvStringToJson(itemProto);
const proto = getProto();
s.start('Transforming');
s.start('Transforming special_item_group.txt');
const input = Bun.file('./input/special_item_group.txt');
if (!input.exists()) {
@ -138,6 +145,58 @@ await match(fileType)
),
);
})
.with('blend', async () => {
const s = spinner();
s.start('Transforming blend.txt');
const input = Bun.file('./input/blend.txt');
if (!input.exists()) {
throw new Error('The file input/special_item_group.txt was not found');
}
const blend = await input.text();
const REGEX =
/section\s+[\s\S]*?item_vnum\s+(\d+)[\s\S]*?apply_type\s+(\S+)[\s\S]*?apply_value\s+([\d\s]+)[\s\S]*?apply_duration\s+([\d\s]+)[\s\S]*?end/gim;
const matches = Array.from(blend.matchAll(REGEX)).map(
([_, vnum, apply_type, values, durations]) => {
const validDurations = durations.trim().split(/\t/);
return {
vnum: parseInt(vnum, 10),
apply_type,
apply_data: values
.trim()
.split(/\t/)
.map((value, index) => ({
value: parseInt(value, 10),
duration: parseInt(validDurations[index], 10),
})),
};
},
);
s.stop('blend.txt was transformed');
const out = Bun.file('./output/blend.json');
if (await out.exists()) {
await out.delete();
}
out.write(
JSON.stringify(
{
$schema:
'https://raw.githubusercontent.com/WildEgo/m2-json-schemas/refs/heads/main/blend.json',
rows: matches,
},
null,
2,
),
);
})
.otherwise(() => {
outro(color.bgRed('Invalid file type'));
process.exit(1);

45
schemas/blend.json Normal file
View File

@ -0,0 +1,45 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/WildEgo/m2-json-schemas/refs/heads/main/blend.json",
"title": "Blend configuration",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"rows": {
"type": "array",
"items": {
"type": "object",
"properties": {
"vnum": {
"type": "integer"
},
"apply_type": {
"type": "string"
},
"apply_data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"value": {
"type": "integer"
},
"duration": {
"type": "integer"
}
},
"required": ["value", "duration"],
"additionalProperties": false
}
}
},
"required": ["vnum", "apply_type", "apply_data"],
"additionalProperties": false
}
}
},
"required": ["rows"],
"additionalProperties": false
}

View File

@ -1,6 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://localhost:8080/$schemas/give_basic_weapon.json",
"$id": "https://raw.githubusercontent.com/WildEgo/m2-json-schemas/refs/heads/main/give_basic_weapon.json",
"title": "Starting items configuration",
"type": "object",
"properties": {
"$schema": {

View File

@ -1,6 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://localhost:8080/$schemas/special_item_group.json",
"$id": "https://raw.githubusercontent.com/WildEgo/m2-json-schemas/refs/heads/main/special_item_group.json",
"title": "Special item group configuration",
"type": "object",
"properties": {
"$schema": {