This repository has been archived on 2021-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
shapez.io/src/js/core/atlas_definitions.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-05-09 16:45:23 +02:00
/**
2020-08-06 11:28:28 +02:00
* @typedef {{ w: number, h: number }} Size
* @typedef {{ x: number, y: number }} Position
2020-05-09 16:45:23 +02:00
* @typedef {{
2020-08-06 11:28:28 +02:00
* frame: Position & Size,
* rotated: boolean,
* spriteSourceSize: Position & Size,
* sourceSize: Size,
* trimmed: boolean
2020-05-09 16:45:23 +02:00
* }} SpriteDefinition
2020-08-06 11:28:28 +02: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 16:45:23 +02:00
*/
export class AtlasDefinition {
2020-08-06 11:28:28 +02:00
/**
* @param {SourceData} sourceData
*/
constructor({ frames, meta }) {
this.meta = meta;
this.sourceData = frames;
this.sourceFileName = meta.image;
2020-05-09 16:45:23 +02:00
}
getFullSourcePath() {
return this.sourceFileName;
}
}
2020-08-06 11:28:28 +02:00
/** @type {AtlasDefinition[]} **/
2020-05-09 16:45:23 +02:00
export const atlasFiles = require
2020-05-14 08:56:18 +02:00
// @ts-ignore
2020-05-09 16:45:23 +02: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));