Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

675 changes: 675 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,19 @@ In node, returns a plain object with the `data` as a Uint8ClampedArray, the `wid

## License

[MIT](./LICENSE)
[GPL-3.0](./LICENSE.md)

Copyright (C) 2018 Renée Kooi <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"version": "1.1.0",
"author": "René Kooi <[email protected]>",
"dependencies": {
"awestruct": "^1.0.0"
"awestruct": "^1.0.0",
"nanoassert": "^1.1.0"
},
"devDependencies": {
"buble": "^0.19.3",
"jascpal": "^0.1.4",
"pngjs": "^3.3.0",
"rimraf": "^2.6.2",
"standard": "^10.0.0"
"standard": "^10.0.0",
"tape": "^4.8.0"
},
"keywords": [
"age of empires",
Expand All @@ -18,12 +22,12 @@
"graphics",
"slp"
],
"license": "MIT",
"license": "GPL-3.0",
"main": "lib/SLP.js",
"repository": "goto-bus-stop/genie-slp",
"scripts": {
"build": "rimraf lib && buble src -o lib",
"prepublish": "npm run build",
"test": "standard src/*.js"
"test": "node test && standard src/*.js test/*.js"
}
}
31 changes: 5 additions & 26 deletions src/SLP.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const Struct = require('awestruct')
const assert = require('nanoassert')
const createImageData = require('./createImageData')

const t = Struct.types
const headerStruct = require('./header')

module.exports = SLP

Expand Down Expand Up @@ -32,27 +31,6 @@ const RENDER_OUTLINE = 0x05
const RENDER_FILL = 0x06
const RENDER_PLAYER_FILL = 0x07

// SLP Header
let headerStruct = Struct({
version: t.string(4),
numFrames: t.int32,
comment: t.string(24),

frames: t.array('numFrames', Struct({
cmdTableOffset: t.uint32,
outlineTableOffset: t.uint32,
paletteOffset: t.uint32,
properties: t.uint32,

width: t.int32,
height: t.int32,
hotspot: Struct({
x: t.int32,
y: t.int32
})
}))
})

const getPlayerColor = (pal, idx, player) => pal[idx + 16 * player]

/**
Expand Down Expand Up @@ -82,13 +60,13 @@ function SLP (buf) {
* Parses the .SLP header.
*/
SLP.prototype.parseHeader = function () {
const header = headerStruct(this.buf)
const header = headerStruct.decode(this.buf)
this.version = header.version
this.numFrames = header.numFrames
this.comment = header.comment
this.frames = header.frames

this.bodyOffset = /* header */ 32 + /* frames */ 32 * header.numFrames
this.bodyOffset = headerStruct.decode.bytes
}

/**
Expand Down Expand Up @@ -128,6 +106,7 @@ SLP.prototype.parseFrame = function (id) {
y++
} else if (lowBits === SLP_COLOR_LIST) {
pxCount = cmd >> 2
assert.ok(pxCount > 0, 'genie-slp: found color list of length 0')
while (pxCount--) {
offset++
commands.push({ command: RENDER_COLOR, arg: /* color */ buf[offset] })
Expand Down
Loading