mdx-m3-viewer
Version:
A browser WebGL model viewer. Mainly focused on models of the games Warcraft 3 and Starcraft 2.
66 lines (46 loc) • 1.53 kB
JavaScript
import UnitsDoo from '../../parsers/w3x/unitsdoo/file';
import Unit from '../../parsers/w3x/unitsdoo/unit';
import LuaContext from './context';
import JassUnit from './types/unit';
/**
* @param {War3Map} map
* @param {string} commonj
* @param {string} blizzardj
* @param {function} callback
*/
export default function rebuild(map, commonj, blizzardj, callback) {
let context = new LuaContext(map);
let start = performance.now();
let time = (msg) => {
callback(`[${(performance.now() - start) | 0}] ${msg}`);
};
time('Converting and running common.j');
context.run(commonj, true);
time('Converting and running Blizzard.j');
context.run(blizzardj, true);
time('Converting and running war3map.j');
context.open(map);
time('Running config()');
context.call('config');
time('Running main()');
context.call('main');
time('Collecting handles');
let unitsFile = new UnitsDoo();
let units = unitsFile.units;
for (let handle of context.handles) {
if (handle instanceof JassUnit) {
let unit = new Unit();
unit.id = handle.unitId;
unit.location[0] = handle.x;
unit.location[1] = handle.y;
// For z need the height of the terrain!
unit.angle = handle.face / 180 * Math.PI;
unit.player = handle.player.index;
unit.targetAcquisition = handle.acquireRange;
units.push(unit);
}
}
time(`Saving war3mapUnits.doo with ${units.length} objects`);
map.set('war3mapUnits.doo', unitsFile.save());
time('Finished');
}