Skip to content

Commit 06d3807

Browse files
committed
Move SLP header struct to a file
1 parent 7495fbb commit 06d3807

File tree

3 files changed

+26
-48
lines changed

3 files changed

+26
-48
lines changed

src/SLP.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const Struct = require('awestruct')
21
const createImageData = require('./createImageData')
3-
4-
const t = Struct.types
2+
const headerStruct = require('./header')
53

64
module.exports = SLP
75

@@ -32,27 +30,6 @@ const RENDER_OUTLINE = 0x05
3230
const RENDER_FILL = 0x06
3331
const RENDER_PLAYER_FILL = 0x07
3432

35-
// SLP Header
36-
let headerStruct = Struct({
37-
version: t.string(4),
38-
numFrames: t.int32,
39-
comment: t.string(24),
40-
41-
frames: t.array('numFrames', Struct({
42-
cmdTableOffset: t.uint32,
43-
outlineTableOffset: t.uint32,
44-
paletteOffset: t.uint32,
45-
properties: t.uint32,
46-
47-
width: t.int32,
48-
height: t.int32,
49-
hotspot: Struct({
50-
x: t.int32,
51-
y: t.int32
52-
})
53-
}))
54-
})
55-
5633
const getPlayerColor = (pal, idx, player) => pal[idx + 16 * player]
5734

5835
/**

src/SLPEncoder.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const Struct = require('awestruct')
2-
3-
const t = Struct.types
1+
const headerStruct = require('./header')
42

53
module.exports = SLPEncoder
64

@@ -31,27 +29,6 @@ const RENDER_OUTLINE = 0x05
3129
const RENDER_FILL = 0x06
3230
const RENDER_PLAYER_FILL = 0x07
3331

34-
// SLP Header
35-
const headerStruct = Struct({
36-
version: t.string(4),
37-
numFrames: t.int32,
38-
comment: t.string(24),
39-
40-
frames: t.array('numFrames', Struct({
41-
cmdTableOffset: t.uint32,
42-
outlineTableOffset: t.uint32,
43-
paletteOffset: t.uint32,
44-
properties: t.uint32,
45-
46-
width: t.int32,
47-
height: t.int32,
48-
hotspot: Struct({
49-
x: t.int32,
50-
y: t.int32
51-
})
52-
}))
53-
})
54-
5532
function last (arr) {
5633
return arr[arr.length - 1]
5734
}

src/header.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const Struct = require('awestruct')
2+
3+
const t = Struct.types
4+
5+
// SLP Header
6+
module.exports = Struct({
7+
version: t.string(4),
8+
numFrames: t.int32,
9+
comment: t.string(24),
10+
11+
frames: t.array('numFrames', Struct({
12+
cmdTableOffset: t.uint32,
13+
outlineTableOffset: t.uint32,
14+
paletteOffset: t.uint32,
15+
properties: t.uint32,
16+
17+
width: t.int32,
18+
height: t.int32,
19+
hotspot: Struct({
20+
x: t.int32,
21+
y: t.int32
22+
})
23+
}))
24+
})

0 commit comments

Comments
 (0)