-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76,515 additions
and
0 deletions.
There are no files selected for viewing
76,295 changes: 76,295 additions & 0 deletions
76,295
(10)trymemode.stormmap/base.stormdata/Mods/HeroesMod/ModelMimic.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const buildMimicXML = require('./helper/buildmimicXML'); | ||
|
||
const prefix = 'UN'; | ||
|
||
buildMimicXML({ | ||
catalogTypeRegex: /^CModel/i, | ||
saveLocation: process.env.TOOLS_MIMC_MODEL_XML_GENERATION_LOCATION, | ||
generation: { | ||
header: { | ||
generatedCommand: 'npm run build:mimicmodels', | ||
description: [ | ||
'It will find all <CModel*> and map to a <CUnit>,', | ||
'That allow a model to be spawned as a Unit.', | ||
`To prevent collision, all Mimic Models Unit's id will have prefixed "${prefix}"`, | ||
], | ||
}, | ||
pre: [ | ||
{ | ||
CUnit: { | ||
$: { | ||
id: `${prefix}_t`, | ||
parent: 'StormHero', | ||
}, | ||
BehaviorArray: [ | ||
{ | ||
$: { Link: 'PermaInvulnerable' }, | ||
}, | ||
], | ||
WeaponArray: [ | ||
{ | ||
$: { Link: 'FootmanMinion' }, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
main: (type, xmlData) => { | ||
const { id } = xmlData.$; | ||
// console.log(`Mapped Model ${id} to Unit ${prefix}${id}.`); | ||
return [ | ||
{ | ||
CUnit: { | ||
$: { | ||
id: `${prefix}${id}`, | ||
parent: `${prefix}_t`, | ||
}, | ||
}, | ||
}, | ||
{ | ||
CActorUnit: { | ||
$: { | ||
id: `${prefix}${id}`, | ||
parent: 'GenericUnitStandard', | ||
unitName: `${prefix}${id}`, | ||
}, | ||
Model: { | ||
$: { | ||
value: id, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-disable require-jsdoc */ | ||
const xml2js = require('xml2js'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const HeroesFiles = require('./HeoresFileWalker'); | ||
const autoXMLinclude = require('./autoXMLinclude'); | ||
|
||
module.exports = (configParam) => { | ||
const config = { | ||
filesSearchRegex: HeroesFiles.AllXMLs, | ||
catalogTypeRegex: /^CAbilEffectTarget/i, | ||
saveLocation: './default.xml', | ||
generation: { | ||
header: { | ||
generatedCommand: 'npm run xxxx', | ||
description: 'Completely devoid of any description whatsoever.', | ||
}, | ||
pre: [], | ||
main: (type, xmlData) => ({ [type]: xmlData }), | ||
}, | ||
...configParam, | ||
}; | ||
|
||
// ================= Generation of file ================= | ||
|
||
// xml2js.Builder() does not allow to add comments... | ||
const builder = new xml2js.Builder({ | ||
rootName: 'Catalog', | ||
xmldec: { | ||
version: '1.0', | ||
encoding: 'us-ascii', | ||
standalone: false, | ||
}, | ||
}); | ||
|
||
const mainObj = {}; | ||
|
||
if (config.generation.pre !== null) { | ||
config.generation.pre.forEach((o) => { | ||
// Check if key exist | ||
const key = Object.keys(o); | ||
if (mainObj[key] === undefined) mainObj[key] = []; | ||
mainObj[key].push(o[key]); | ||
}); | ||
} | ||
|
||
HeroesFiles | ||
.ReadEach(config.filesSearchRegex) | ||
.forEach((file) => { | ||
xml2js.parseString(file.fileData, (error, result) => { | ||
if (error) throw error; | ||
|
||
// Main <Catalog> data | ||
const catalog = result.Catalog; | ||
if (catalog === undefined || catalog === null) return; | ||
|
||
// Read of the entry, such as <CBehaviorBuff>, <CAbilEffectInstant> ... | ||
Object.entries(catalog) | ||
.forEach((entries) => { | ||
// e.g BehaviorBuff | ||
const catalogType = entries[0]; | ||
// Does not match type | ||
if (!config.catalogTypeRegex.test(catalogType)) return; | ||
|
||
entries[1].forEach((entry) => { | ||
const catalogEntry = entry.$.id; | ||
if (catalogEntry === undefined || catalogEntry === null) return; | ||
|
||
// Returned function | ||
const obj = config.generation.main(catalogType, entry); | ||
|
||
if (obj === undefined || obj === null || !Array.isArray(obj)) return; | ||
|
||
obj.forEach((o) => { | ||
// Check if key exist | ||
const key = Object.keys(o); | ||
if (mainObj[key] === undefined) mainObj[key] = []; | ||
mainObj[key].push(o[key]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
let finalXML = builder.buildObject(mainObj); | ||
|
||
// Inject Comments into the built XML, since builder does not support adding comments | ||
|
||
finalXML = finalXML.split('\n'); | ||
|
||
let { description } = config.generation.header; | ||
|
||
if (typeof description === 'string') { | ||
description = description.split('\n'); | ||
} | ||
|
||
finalXML[0] = `${finalXML[0]} | ||
<!-- ======================================================== --> | ||
<!-- This file is generated via "${config.generation.header.generatedCommand}" --> | ||
<!-- ======================================================== --> | ||
${description | ||
.map((d) => `<!-- ${d} -->`) | ||
.join('\n') | ||
} | ||
`; | ||
finalXML = finalXML.join('\n'); | ||
|
||
console.log('==================='); | ||
|
||
// Check if parent directory exist | ||
if (!fs.existsSync(path.dirname(config.saveLocation))) { | ||
fs.mkdirSync( | ||
path.dirname(config.saveLocation), { | ||
recursive: true, | ||
}, | ||
); | ||
console.log(`Created directory: ${path.dirname(config.saveLocation)}`); | ||
} | ||
|
||
// Save file | ||
fs.writeFileSync( | ||
config.saveLocation, | ||
finalXML, | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
console.log(`Created file: ${config.saveLocation}`); | ||
console.log('==================='); | ||
|
||
// Generate XML | ||
autoXMLinclude(); | ||
}; |