1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +00:00
tobspr_shapez.io/src/js/core/atlas_definitions.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-05-09 14:45:23 +00:00
/**
2020-08-06 09:28:28 +00:00
* @typedef {{ w: number, h: number }} Size
* @typedef {{ x: number, y: number }} Position
2020-05-09 14:45:23 +00:00
* @typedef {{
2020-08-06 09:28:28 +00:00
* frame: Position & Size,
* rotated: boolean,
* spriteSourceSize: Position & Size,
* sourceSize: Size,
* trimmed: boolean
2020-05-09 14:45:23 +00:00
* }} SpriteDefinition
2020-08-06 09:28:28 +00:00
*
* @typedef {{
* app: string,
* version: string,
* image: string,
* format: string,
* size: Size,
* scale: string,
* smartupdate: string
* }} AtlasMeta
*
* @typedef {{
* frames: Object.<string, SpriteDefinition>,
* meta: AtlasMeta
* }} SourceData
2020-05-09 14:45:23 +00:00
*/
export class AtlasDefinition {
2020-08-06 09:28:28 +00:00
/**
* @param {SourceData} sourceData
*/
constructor({ frames, meta }) {
this.meta = meta;
this.sourceData = frames;
this.sourceFileName = meta.image;
2020-05-09 14:45:23 +00:00
}
getFullSourcePath() {
return this.sourceFileName;
}
}
2020-08-06 09:28:28 +00:00
/** @type {AtlasDefinition[]} **/
2020-05-09 14:45:23 +00:00
export const atlasFiles = require
2020-05-14 06:56:18 +00:00
// @ts-ignore
2020-05-09 14:45:23 +00:00
.context("../../../res_built/atlas/", false, /.*\.json/i)
.keys()
.map(f => f.replace(/^\.\//gi, ""))
.map(f => require("../../../res_built/atlas/" + f))
.map(data => new AtlasDefinition(data));