Skip to content

Commit 387fd92

Browse files
committed
added support for custom art formatsgit add .
1 parent 07d17f8 commit 387fd92

File tree

4 files changed

+56
-26
lines changed

4 files changed

+56
-26
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ Mapping output can be configured to either reduce the number of tiles, or the nu
8282

8383
Both methods of importing use CIEDE2000 nearest colour matching to the current palette.
8484

85-
## Custom Mappings
85+
## Custom Formats
8686

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

89-
The base mapping formats are provided in the `scripts/` directory. These can be modified to suit whatever format you decide to come up with.
89+
The base formats are provided in the `scripts/` directory. These can be modified to suit whatever format you decide to come up with.
90+
91+
You can provide custom mapping formats, DPLCs formats, art formats (including compression) and palette formats.
9092

9193
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.

TODO

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ definition([
1616
many(art()),
1717
])
1818

19-
// provide custom art function
20-
// custom asm parser
2119
// custom palettes
20+
// custom asm parser
2221

2322
/* https://unix.stackexchange.com/questions/585645/launch-an-application-by-a-double-click */
2423
// provide a custom definition, but have a default
@@ -33,8 +32,8 @@ definition([
3332

3433
// formats to support
3534

36-
// kid chameleon
3735
// crackers
36+
// kid chameleon
3837
// chaotix
3938
// s3k sonic saving
4039
// plane mappings / snap to

app/components/file/file-object.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ const compressionList = Object.keys(compressionFormats);
2424
export const FileObject = observer(({ obj }) => {
2525
scripts.length; // react to script updates
2626
const script = obj.format && runScript(obj.format);
27+
const scriptSafe = script && !script.error;
2728

2829
const { isAbsolute } = obj; // set in store/workspace
2930

3031
const mappingsASM = extname(obj.mappings.path) === '.asm';
3132
const dplcsASM = extname(obj.dplcs.path) === '.asm';
3233
const linesLeft = obj.palettes.reduce((a, c) => a - c.length, 4);
3334

34-
const scriptDPLCs = script && !script.error && script.hasDPLCs;
35+
const scriptDPLCs = scriptSafe && script.DPLCs;
36+
const scriptArt = scriptSafe && script.art;
3537
const toggleDPLCs = () => (obj.dplcs.enabled = !obj.dplcs.enabled);
3638

3739

3840
function ioWrap(filePath, setError, e, cb) {
3941
setError();
40-
if (script && !script.error && filePath) {
42+
if (scriptSafe && filePath) {
4143
const done = SaveLoad.indicator(e);
4244
requestIdleCallback(async () => {
4345
const path = isAbsolute
@@ -79,7 +81,9 @@ export const FileObject = observer(({ obj }) => {
7981
function loadArt(e) {
8082
ioWrap(obj.art.path, setArtError, e, async (path) => {
8183
const buffer = (await fs.readFile(path)).slice(obj.art.offset || 0);
82-
const tiles = bufferToTiles(buffer, obj.art.compression);
84+
const tiles = scriptArt
85+
? script.readArt(buffer)
86+
: bufferToTiles(buffer, obj.art.compression);
8387
environment.tiles.replace(tiles);
8488
});
8589
}
@@ -89,7 +93,9 @@ export const FileObject = observer(({ obj }) => {
8993
if (obj.art.offset) {
9094
throw new Error('Can only save art at offset 0');
9195
}
92-
const tiles = tilesToBuffer(environment.tiles, obj.art.compression);
96+
const tiles = scriptArt
97+
? script.writeArt(tiles)
98+
: tilesToBuffer(environment.tiles, obj.art.compression);
9399
await fs.writeFile(path, tiles);
94100
});
95101
}
@@ -235,18 +241,22 @@ export const FileObject = observer(({ obj }) => {
235241
<Item color="green">Art</Item>
236242
<SaveLoad load={loadArt} save={saveArt} />
237243
</div>
238-
<div className="menu-item">
239-
<Item>Compression</Item>
240-
<Select
241-
options={compressionList}
242-
store={obj.art}
243-
accessor="compression"
244-
/>
245-
</div>
246-
<div className="menu-item">
247-
<Item>Offset</Item>
248-
<Input store={obj.art} accessor="offset" isNumber />
249-
</div>
244+
{!scriptArt && (
245+
<>
246+
<div className="menu-item">
247+
<Item>Compression</Item>
248+
<Select
249+
options={compressionList}
250+
store={obj.art}
251+
accessor="compression"
252+
/>
253+
</div>
254+
<div className="menu-item">
255+
<Item>Offset</Item>
256+
<Input store={obj.art} accessor="offset" isNumber />
257+
</div>
258+
</>
259+
)}
250260
<ErrorMsg error={artError} />
251261
<FileInput
252262
label="Art"

app/formats/scripts/run-script.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ export default catchFunc((file) => {
119119
const [write, setWrite] = useFunc();
120120
const [read, setRead] = useFunc();
121121

122+
const [artArgs, artFunc] = useDef();
122123
const [mappingArgs, mappingFunc] = useDef();
123124
const [dplcArgs, dplcFunc] = useDef();
124125

125126
(new Function('Flex2', loadScript(file)))({
126127
...constants,
127128
write,
128129
read,
130+
art: artFunc,
129131
mappings: mappingFunc,
130132
dplcs: dplcFunc,
131133
offsetTable: makeOffsetTable({ read, write }),
@@ -285,11 +287,28 @@ export default catchFunc((file) => {
285287
const writeMappings = createWriter(mappingArgs[0]);
286288
const writeDPLCs = createWriter(dplcArgs[0]);
287289

288-
return {
290+
const methods = {
291+
mappings: true,
289292
readMappings,
290293
writeMappings,
291-
hasDPLCs: !!dplcArgs[0],
292-
readDPLCs,
293-
writeDPLCs,
294294
};
295+
296+
if (dplcArgs[0]) {
297+
Object.assign(methods, {
298+
DPLCs: true,
299+
readDPLCs,
300+
writeDPLCs,
301+
});
302+
}
303+
304+
if (artArgs[0]) {
305+
const [readArt, writeArt] = artArgs[0];
306+
Object.assign(methods, {
307+
art: true,
308+
readArt,
309+
writeArt,
310+
});
311+
}
312+
313+
return methods;
295314
});

0 commit comments

Comments
 (0)