add: blend.json support.
parent
320cb7342c
commit
76e7d92eee
63
index.ts
63
index.ts
|
|
@ -24,9 +24,16 @@ const fileType = await select({
|
||||||
value: 'special_item_group',
|
value: 'special_item_group',
|
||||||
label: 'special_item_group.txt',
|
label: 'special_item_group.txt',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: 'blend',
|
||||||
|
label: 'blend.txt',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getProto = () =>
|
||||||
|
csvToJson.fieldDelimiter('\t').csvStringToJson(itemProto);
|
||||||
|
|
||||||
if (isCancel(fileType)) {
|
if (isCancel(fileType)) {
|
||||||
cancel('Operation cancelled');
|
cancel('Operation cancelled');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|
@ -36,9 +43,9 @@ await match(fileType)
|
||||||
.with('special_item_group', async () => {
|
.with('special_item_group', async () => {
|
||||||
const s = spinner();
|
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');
|
const input = Bun.file('./input/special_item_group.txt');
|
||||||
if (!input.exists()) {
|
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(() => {
|
.otherwise(() => {
|
||||||
outro(color.bgRed('Invalid file type'));
|
outro(color.bgRed('Invalid file type'));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"$schema": {
|
"$schema": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"$schema": {
|
"$schema": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue