Skip to content

Commit

Permalink
import fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kirjavascript committed Oct 29, 2023
1 parent e2b6f6c commit c0aad5a
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 52 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG
@@ -1,12 +1,13 @@
# Changelog

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

## [1.2.2]
- Added sprite rotation algorithm: 3 shears
Expand Down
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -84,12 +84,8 @@ Both methods of importing use CIEDE2000 nearest colour matching to the current p

## Custom Formats

As of version 1.0.0, Flex 2 supports a wider array of formats and allows you to specify your own.

The base formats are provided in the `scripts/` directory. These can be modified to suit whatever format you decide to come up with.

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

Ability to provide a custom ASM parser is also available.

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.
Full macro support is available for assembly files, along with the ability to specify custom output.
2 changes: 2 additions & 0 deletions TODO
Expand Up @@ -15,6 +15,8 @@ macros for mappings
perf
autoload mapping label if blank

metadata for mappings

redo tile rendering
remove rotsprite

Expand Down
9 changes: 5 additions & 4 deletions app/components/import/remove-background.js
Expand Up @@ -3,15 +3,16 @@ export function removeBackground(buffer) {
const [r, g, b, a] = buffer.data;
// strip background colour
if (a > 0x80) {
// tfw lambdas are five times slower than a for loop...
for (let j = 0; j < (buffer.data.length); j+=4) {
if (
r == buffer.data[j] &&
g == buffer.data[j+1] &&
b == buffer.data[j+2]
r === buffer.data[j] &&
g === buffer.data[j+1] &&
b === buffer.data[j+2]
) {
buffer.data[j+3] = 0;
}
}
}

return buffer;
}
5 changes: 1 addition & 4 deletions app/components/import/state.js
Expand Up @@ -125,14 +125,11 @@ class ImportState {
};

importSprites = () => {
const { ctx, canvas } = this;
const { width, height } = canvas;
const buffer = ctx.getImageData(0, 0, width, height);
const sprites = this.bboxes.map(({x, y, width, height}) => {
return {
width,
height,
buffer: ctx.getImageData(x, y, width, height),
buffer: this.ctx.getImageData(x, y, width, height),
};
});

Expand Down
4 changes: 4 additions & 0 deletions app/formats/image.js
Expand Up @@ -3,6 +3,7 @@ const { dialog } = require('@electron/remote');
import { readFile, writeFile } from 'fs';
import { errorMsg } from '#util/dialog';
import { colorMatch } from '#components/import/color-match';
import { removeBackground } from '#components/import/remove-background';

export function exportSprite({ buffer, mappings }) {

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

// remove background if not transparent
ctx.putImageData(removeBackground(ctx.getImageData(0, 0, img.width, img.height)), 0, 0);

// convert to tiles

mappings.forEach(async ({ top, left, palette, vflip, hflip, width, height, art }) => {
Expand Down
62 changes: 31 additions & 31 deletions development/build.sh
Expand Up @@ -2,35 +2,35 @@
# copy latest version of electron remote
cp -r node_modules/@electron/remote ./static
node -e "require('./development/build')()"
# npx electron-packager ./static Flex2 --platform=win32 --arch=x64 \
# --asar --overwrite --package-manager yarn \
# --win32metadata.CompanyName="Flex 2" \
# --win32metadata.FileDescription="Flex 2" \
# --win32metadata.ProductName="Flex 2" \
# --appCopyright="kirjavascript" \
# --icon=./development/icon.ico
# npx electron-packager ./static Flex2 --platform=win32 --arch=ia32 \
# --asar --overwrite --package-manager yarn \
# --win32metadata.CompanyName="Flex 2" \
# --win32metadata.FileDescription="Flex 2" \
# --win32metadata.ProductName="Flex 2" \
# --appCopyright="kirjavascript" \
# --icon=./development/icon.ico
npx electron-packager ./static Flex2 --platform=win32 --arch=x64 \
--asar --overwrite --package-manager yarn \
--win32metadata.CompanyName="Flex 2" \
--win32metadata.FileDescription="Flex 2" \
--win32metadata.ProductName="Flex 2" \
--appCopyright="kirjavascript" \
--icon=./development/icon.ico
npx electron-packager ./static Flex2 --platform=win32 --arch=ia32 \
--asar --overwrite --package-manager yarn \
--win32metadata.CompanyName="Flex 2" \
--win32metadata.FileDescription="Flex 2" \
--win32metadata.ProductName="Flex 2" \
--appCopyright="kirjavascript" \
--icon=./development/icon.ico
npx electron-packager ./static Flex2 --platform=linux --arch=x64 --asar --overwrite --package-manager yarn
# npx electron-packager ./static Flex2 --platform=darwin --arch=x64 --asar --overwrite --package-manager yarn
npx electron-packager ./static Flex2 --platform=darwin --arch=x64 --asar --overwrite --package-manager yarn


# cp -r scripts Flex2-win32-ia32
# cd Flex2-win32-ia32
# zip -r ../flex2-win32-ia32.zip *
# cd ..
# rm -r Flex2-win32-ia32
cp -r scripts Flex2-win32-ia32
cd Flex2-win32-ia32
zip -r ../flex2-win32-ia32.zip *
cd ..
rm -r Flex2-win32-ia32

# cp -r scripts Flex2-win32-x64
# cd Flex2-win32-x64
# zip -r ../flex2-win32-x64.zip *
# cd ..
# rm -r Flex2-win32-x64
cp -r scripts Flex2-win32-x64
cd Flex2-win32-x64
zip -r ../flex2-win32-x64.zip *
cd ..
rm -r Flex2-win32-x64

cp -r scripts Flex2-linux-x64
cd Flex2-linux-x64
Expand All @@ -39,9 +39,9 @@ tar cfvz ../flex2-linux-x64.tar.gz *
cd ..
rm -r Flex2-linux-x64

# cp -r scripts Flex2-darwin-x64
# cd Flex2-darwin-x64
# chmod a+x Flex2
# tar cfvz ../flex2-osx-x64.tar.gz *
# cd ..
# rm -r Flex2-darwin-x64
cp -r scripts Flex2-darwin-x64
cd Flex2-darwin-x64
chmod a+x Flex2
tar cfvz ../flex2-osx-x64.tar.gz *
cd ..
rm -r Flex2-darwin-x64
4 changes: 2 additions & 2 deletions scripts/Sonic 1.js
Expand Up @@ -82,7 +82,7 @@ SonicDplcVer := 1
/**
* MapMacros Mapping output
*
* delete this function to output raw data instead
* remove this to output raw data instead
*/
writeMappings(({ label, sprites, renderHex }) => {
const list = [];
Expand Down Expand Up @@ -124,7 +124,7 @@ SonicDplcVer := 1
/**
* MapMacros DPLC output
*
* delete this function to output raw data instead
* remove this to output raw data instead
*/
writeDPLCs(({ label, sprites, renderHex }) => {
const list = [];
Expand Down
4 changes: 2 additions & 2 deletions scripts/Sonic 2.js
Expand Up @@ -93,7 +93,7 @@ SonicDplcVer = 2
/**
* MapMacros Mapping output
*
* delete this function to output raw data instead
* remove this to output raw data instead
*/
writeMappings(({ label, sprites, renderHex }) => {
const list = [];
Expand Down Expand Up @@ -135,7 +135,7 @@ SonicDplcVer = 2
/**
* MapMacros DPLC output
*
* delete this function to output raw data instead
* remove this to output raw data instead
*/
writeDPLCs(({ label, sprites, renderHex }) => {
const list = [];
Expand Down
4 changes: 2 additions & 2 deletions scripts/Sonic 3&K Sonic.js
Expand Up @@ -33,7 +33,7 @@ mappings([
if (frameIndex === quantity - 1) return endFrame;
});
},
() => { throw new Error('convert to S3K Player instead'); },
() => { throw new Error('unsupported'); },
],
]);

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

0 comments on commit c0aad5a

Please sign in to comment.