diff --git a/Aseprite.js b/Aseprite.js index f091099..c4f40a5 100644 --- a/Aseprite.js +++ b/Aseprite.js @@ -23,6 +23,23 @@ class Aseprite { this.tilesets = []; } + //#region Static Constants + + /** + * Map of the possible flag values for a Layer + */ + static LAYER_FLAG_MAP = { + visible: 0b1, + editable: 0b10, + lockMovement: 0b100, + background: 0b1000, + preferLinkedCels: 0b10000, + collapsedGroup: 0b100000, + reference: 0b1000000 + }; + + //#endregion Static Constants + /** * Reads the next byte (8-bit unsigned) value in the buffer * @@ -212,6 +229,27 @@ class Aseprite { this._offset += numBytes; } + /** + * Translates the listed flags for a layer into true/false values + * dictating whether or not that flag is "on"(true) or "off"(false) + * + * @private + * @param {object} flagMap Object of flags and their binary value + * @param {number} flagValue Value of the layer flags + * @returns {object} Map of the flags and if they are true or false + */ + #translateFlags(flagValue) { + // Create an object to put the flags and their "toggle" (true/false) + const translatedFlagMap = {}; + // Iterate through the flags and their binary value, use bitwise op + // to see if the flag is present in the "layer flags" and add the + // flag to the map with the accompanying "toggle" + for( const flag in Aseprite.LAYER_FLAG_MAP) { + translatedFlagMap[flag] = (flagValue & Aseprite.LAYER_FLAG_MAP[flag]) == Aseprite.LAYER_FLAG_MAP[flag]; + } + return translatedFlagMap; + } + /** * Reads the 128-byte header of an Aseprite file and stores the information * @@ -501,7 +539,7 @@ class Aseprite { */ readLayerChunk() { const layer = {} - layer.flags = this.readNextWord(); + layer.flags = this.#translateFlags(this.readNextWord()); layer.type = this.readNextWord(); layer.layerChildLevel = this.readNextWord(); this.skipBytes(4); diff --git a/README.md b/README.md index 2205e0c..a049b4b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![npm](https://img.shields.io/npm/v/ase-parser.svg)](https://www.npmjs.com/package/ase-parser) +[![npm](https://img.shields.io/npm/dt/ase-parser.svg?maxAge=3600)](https://www.npmjs.com/package/ase-parser) +[![install size](https://packagephobia.now.sh/badge?p=ase-parser)](https://packagephobia.now.sh/result?p=ase-parser) + # ase-parser Parse Aseprite files with Node.js, no external dependencies. @@ -151,7 +155,7 @@ aseFile.parse(); ## Layer Object | Field | Type | Description | |-----------------|---------|-------------------------------| -| flags | integer | flags for the layer | +| flags | [layer flags](#layer-flags-object) | flags for the layer translated into a map | | type | integer | type | | layerChildLevel | integer | layer child level | | opacity | integer | opacity (0-255) | @@ -267,6 +271,19 @@ aseFile.parse(); | x | integer | X position of the pivot | | y | integer | Y position of the pivot | +## Layer Flags Object + +This object is a utility object that will have ***ALL*** fields present. If a field is "on" it will be `true`, if the field is "off" it will be `false`. + +| Field | Description | +|-------|---------| +| visible | Whether or not the layer is visible | +| editable | Whether or not the layer is editable | +| lockMovement | Whether or not the layer is a background layer | +| preferLinkedCels | Whether or not the layer prefers linked cels | +| collapsedGroup | Whether or not the layer group should be displayed collapsed | +| reference | Whether or not the layer is a reference layer | + # Further Info If you would like to read up on the Aseprite file spec: [Spec](https://github.com/aseprite/aseprite/blob/master/docs/ase-file-specs.md) \ No newline at end of file diff --git a/docs/gitflow.md b/docs/gitflow.md new file mode 100644 index 0000000..124c873 --- /dev/null +++ b/docs/gitflow.md @@ -0,0 +1,17 @@ +# Gitflow + +We'll be using the gitflow organization for the repo. I'll describe a TLDR version, but provide links to documents that explain it in further detail. + +### Organization + +The branches listed below will be used for the project. + + * `master` - Contains "production ready" code. i.e. The code that gets pushed to NPM. + * `develop` - Contains code that's currently in progress. This is the branch that should be targeted for PRs. + * `feature/*` - Contains a `feature`. This should be the current work for a single feature/addition to the codebase. It should have a sensible name. Let's say I want to comment all of the code, the feature branch name would be something like `feature/comment-js-files`. + * `release` - This is branched from `develop` when a release is ready and holds the code for a release. It will be used to test to make sure there are no bugs before it gets pushed to `master`. + * `hotfix` - If there is a bug in `master`, a hotfix branch is created with the fix to be merged DIRECTLY into master and then will be merged back into `develop` so that the fix is present in future code. + +### Resources + * [GitKraken](https://www.gitkraken.com/learn/git/git-flow) + * [Atlassian](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) diff --git a/main.yml b/main.yml deleted file mode 100644 index e334b61..0000000 --- a/main.yml +++ /dev/null @@ -1,23 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. -on: - release: - types: [published] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - publish-npm: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: 12 - registry-url: https://registry.npmjs.org/ - - run: npm ci - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/package.json b/package.json index 3878c15..a6b82eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ase-parser", - "version": "0.0.17", + "version": "0.0.18", "description": "Parser for Aseprite files", "main": "Aseprite.js", "typings": "./typings/Aseprite.d.ts", diff --git a/typings/Aseprite.d.ts b/typings/Aseprite.d.ts index 3bf48f6..eb62552 100644 --- a/typings/Aseprite.d.ts +++ b/typings/Aseprite.d.ts @@ -83,7 +83,7 @@ declare namespace Aseprite { color: string; } export interface Layer { - flags: number; + flags: Aseprite.LayerFlags; type: number; layerChildLevel: number; blendMode: number; @@ -125,4 +125,13 @@ declare namespace Aseprite { fGamma: number; icc?: Buffer; } -} \ No newline at end of file + export interface LayerFlags { + visible: boolean; + editable: boolean; + lockMovement: boolean; + background: boolean; + preferLinkedCels: boolean; + collapsedGroup: boolean; + reference: boolean; + } +}