Skip to content

Commit c0aad5a

Browse files
committed
import fix
1 parent e2b6f6c commit c0aad5a

File tree

10 files changed

+53
-52
lines changed

10 files changed

+53
-52
lines changed

CHANGELOG

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Changelog
22

3-
## [unreleased]
3+
## [1.3.0]
44
- Assembler now uses AS Macro Assembler for full macro support
5-
- MapMacros.asm definitions added
5+
- MapMacros.asm definitions added for Sonic 1 and 2
66
- Custom ASM output support added
77
- Make (de)compression threaded
88
- Change DPLC limit to 255
99
- Fix issue where image data would be cached incorrectly
10+
- Fix transparent background colour when importing images over the current sprite
1011

1112
## [1.2.2]
1213
- Added sprite rotation algorithm: 3 shears

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ Both methods of importing use CIEDE2000 nearest colour matching to the current p
8484

8585
## Custom Formats
8686

87-
As of version 1.0.0, Flex 2 supports a wider array of formats and allows you to specify your own.
88-
8987
The base formats are provided in the `scripts/` directory. These can be modified to suit whatever format you decide to come up with.
9088

9189
You can provide custom mapping formats, DPLCs formats, art formats (including compression), and palette formats.
9290

93-
Ability to provide a custom ASM parser is also available.
94-
95-
The definition file format is currently undocumented, and still being expanded on. If you have a request to add support for a new disassembly, or just want more information on the format - open an issue on github with your request.
91+
Full macro support is available for assembly files, along with the ability to specify custom output.

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ macros for mappings
1515
perf
1616
autoload mapping label if blank
1717

18+
metadata for mappings
19+
1820
redo tile rendering
1921
remove rotsprite
2022

app/components/import/remove-background.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ export function removeBackground(buffer) {
33
const [r, g, b, a] = buffer.data;
44
// strip background colour
55
if (a > 0x80) {
6-
// tfw lambdas are five times slower than a for loop...
76
for (let j = 0; j < (buffer.data.length); j+=4) {
87
if (
9-
r == buffer.data[j] &&
10-
g == buffer.data[j+1] &&
11-
b == buffer.data[j+2]
8+
r === buffer.data[j] &&
9+
g === buffer.data[j+1] &&
10+
b === buffer.data[j+2]
1211
) {
1312
buffer.data[j+3] = 0;
1413
}
1514
}
1615
}
16+
17+
return buffer;
1718
}

app/components/import/state.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ class ImportState {
125125
};
126126

127127
importSprites = () => {
128-
const { ctx, canvas } = this;
129-
const { width, height } = canvas;
130-
const buffer = ctx.getImageData(0, 0, width, height);
131128
const sprites = this.bboxes.map(({x, y, width, height}) => {
132129
return {
133130
width,
134131
height,
135-
buffer: ctx.getImageData(x, y, width, height),
132+
buffer: this.ctx.getImageData(x, y, width, height),
136133
};
137134
});
138135

app/formats/image.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { dialog } = require('@electron/remote');
33
import { readFile, writeFile } from 'fs';
44
import { errorMsg } from '#util/dialog';
55
import { colorMatch } from '#components/import/color-match';
6+
import { removeBackground } from '#components/import/remove-background';
67

78
export function exportSprite({ buffer, mappings }) {
89

@@ -208,6 +209,9 @@ export async function importImg() {
208209
const ctx = canvas.getContext('2d');
209210
ctx.drawImage(img, 0, 0);
210211

212+
// remove background if not transparent
213+
ctx.putImageData(removeBackground(ctx.getImageData(0, 0, img.width, img.height)), 0, 0);
214+
211215
// convert to tiles
212216

213217
mappings.forEach(async ({ top, left, palette, vflip, hflip, width, height, art }) => {

development/build.sh

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22
# copy latest version of electron remote
33
cp -r node_modules/@electron/remote ./static
44
node -e "require('./development/build')()"
5-
# npx electron-packager ./static Flex2 --platform=win32 --arch=x64 \
6-
# --asar --overwrite --package-manager yarn \
7-
# --win32metadata.CompanyName="Flex 2" \
8-
# --win32metadata.FileDescription="Flex 2" \
9-
# --win32metadata.ProductName="Flex 2" \
10-
# --appCopyright="kirjavascript" \
11-
# --icon=./development/icon.ico
12-
# npx electron-packager ./static Flex2 --platform=win32 --arch=ia32 \
13-
# --asar --overwrite --package-manager yarn \
14-
# --win32metadata.CompanyName="Flex 2" \
15-
# --win32metadata.FileDescription="Flex 2" \
16-
# --win32metadata.ProductName="Flex 2" \
17-
# --appCopyright="kirjavascript" \
18-
# --icon=./development/icon.ico
5+
npx electron-packager ./static Flex2 --platform=win32 --arch=x64 \
6+
--asar --overwrite --package-manager yarn \
7+
--win32metadata.CompanyName="Flex 2" \
8+
--win32metadata.FileDescription="Flex 2" \
9+
--win32metadata.ProductName="Flex 2" \
10+
--appCopyright="kirjavascript" \
11+
--icon=./development/icon.ico
12+
npx electron-packager ./static Flex2 --platform=win32 --arch=ia32 \
13+
--asar --overwrite --package-manager yarn \
14+
--win32metadata.CompanyName="Flex 2" \
15+
--win32metadata.FileDescription="Flex 2" \
16+
--win32metadata.ProductName="Flex 2" \
17+
--appCopyright="kirjavascript" \
18+
--icon=./development/icon.ico
1919
npx electron-packager ./static Flex2 --platform=linux --arch=x64 --asar --overwrite --package-manager yarn
20-
# npx electron-packager ./static Flex2 --platform=darwin --arch=x64 --asar --overwrite --package-manager yarn
20+
npx electron-packager ./static Flex2 --platform=darwin --arch=x64 --asar --overwrite --package-manager yarn
2121

2222

23-
# cp -r scripts Flex2-win32-ia32
24-
# cd Flex2-win32-ia32
25-
# zip -r ../flex2-win32-ia32.zip *
26-
# cd ..
27-
# rm -r Flex2-win32-ia32
23+
cp -r scripts Flex2-win32-ia32
24+
cd Flex2-win32-ia32
25+
zip -r ../flex2-win32-ia32.zip *
26+
cd ..
27+
rm -r Flex2-win32-ia32
2828

29-
# cp -r scripts Flex2-win32-x64
30-
# cd Flex2-win32-x64
31-
# zip -r ../flex2-win32-x64.zip *
32-
# cd ..
33-
# rm -r Flex2-win32-x64
29+
cp -r scripts Flex2-win32-x64
30+
cd Flex2-win32-x64
31+
zip -r ../flex2-win32-x64.zip *
32+
cd ..
33+
rm -r Flex2-win32-x64
3434

3535
cp -r scripts Flex2-linux-x64
3636
cd Flex2-linux-x64
@@ -39,9 +39,9 @@ tar cfvz ../flex2-linux-x64.tar.gz *
3939
cd ..
4040
rm -r Flex2-linux-x64
4141

42-
# cp -r scripts Flex2-darwin-x64
43-
# cd Flex2-darwin-x64
44-
# chmod a+x Flex2
45-
# tar cfvz ../flex2-osx-x64.tar.gz *
46-
# cd ..
47-
# rm -r Flex2-darwin-x64
42+
cp -r scripts Flex2-darwin-x64
43+
cd Flex2-darwin-x64
44+
chmod a+x Flex2
45+
tar cfvz ../flex2-osx-x64.tar.gz *
46+
cd ..
47+
rm -r Flex2-darwin-x64

scripts/Sonic 1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SonicDplcVer := 1
8282
/**
8383
* MapMacros Mapping output
8484
*
85-
* delete this function to output raw data instead
85+
* remove this to output raw data instead
8686
*/
8787
writeMappings(({ label, sprites, renderHex }) => {
8888
const list = [];
@@ -124,7 +124,7 @@ SonicDplcVer := 1
124124
/**
125125
* MapMacros DPLC output
126126
*
127-
* delete this function to output raw data instead
127+
* remove this to output raw data instead
128128
*/
129129
writeDPLCs(({ label, sprites, renderHex }) => {
130130
const list = [];

scripts/Sonic 2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ SonicDplcVer = 2
9393
/**
9494
* MapMacros Mapping output
9595
*
96-
* delete this function to output raw data instead
96+
* remove this to output raw data instead
9797
*/
9898
writeMappings(({ label, sprites, renderHex }) => {
9999
const list = [];
@@ -135,7 +135,7 @@ SonicDplcVer = 2
135135
/**
136136
* MapMacros DPLC output
137137
*
138-
* delete this function to output raw data instead
138+
* remove this to output raw data instead
139139
*/
140140
writeDPLCs(({ label, sprites, renderHex }) => {
141141
const list = [];

scripts/Sonic 3&K Sonic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mappings([
3333
if (frameIndex === quantity - 1) return endFrame;
3434
});
3535
},
36-
() => { throw new Error('convert to S3K Player instead'); },
36+
() => { throw new Error('unsupported'); },
3737
],
3838
]);
3939

@@ -49,6 +49,6 @@ dplcs([
4949
if (frameIndex + 1 === quantity) return endFrame;
5050
});
5151
},
52-
() => { throw new Error('convert to S3K Player instead'); },
52+
() => { throw new Error('unsupported'); },
5353
],
5454
]);

0 commit comments

Comments
 (0)