Skip to content

Commit 2525414

Browse files
committed
Sprite autozoom
1 parent a5f9305 commit 2525414

File tree

10 files changed

+67
-53
lines changed

10 files changed

+67
-53
lines changed

CHANGELOG

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
- Sonic 2 Special Stage added [#21](/../../issues/21)
77
- Sonic 3&K Sonic/Supersonic partial support
88
- New ASM parser/writer
9-
- Added File menu
9+
- Added File tab
1010
- Create new files / better file selection
1111
- Save/Load individual assets
1212
- Art offset [#15](/../../issues/15)
1313
- Blank entries in palette line
14-
- Rebuilt Project screen
14+
- Rebuilt Project tab
1515
- Tree structure for projects
1616
- Reuse file menu
17-
- Mapping screen updates
17+
- Mapping tab updates
1818
- New mapping autodismiss is configurable
1919
- Added 'close' to new mapping / raw editor
20+
- Sprites tab now autozooms depending on sprite size
2021
- Fixed a keycombination event bug [#29](/../../issues/29)
2122
- Fixed corrupted art when importing transparent PNGs [#22](/../../issues/22)
2223

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</div>
55
<br>
66

7-
Flex 2 is a multi-purpose sprite editor for the Sega Megadrive
7+
Flex 2 is a sprite editor for the Sega Megadrive
88

99
# [download](https://github.com/kirjavascript/Flex2/releases)
1010

TODO

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ definition([
1919
many(art()),
2020
])
2121

22-
// autozoom based on sprite size for sprites tab
22+
// mapping limits
23+
// history / mapping drag slowdown
24+
// update documentation
2325

2426
// crackers first, then kd cham
2527
// UI by definition
@@ -51,7 +53,6 @@ animation editor
5153
BUGS
5254

5355
max mapping qty limit (import screen limits too)
54-
mappings mode in fullscreen raw editor is borked
5556
saving 0 tile as nemesis crashes
5657
saving ArtC42 at all crashes
5758
pink surrounding tiles sometimes breaks

app/components/import/import-sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { environment } from '#store/environment';
2-
import { getCenter } from '#util/get-center';
2+
import { getCenter } from '../mappings/state/bounds';
33
import { concatDPLCs } from '../mappings/state/concat-dplcs';
44

55
function addTile(ctx, x, y, palette) {

app/components/mappings/mapping.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { Component } from 'react';
22
import { Tile } from '../art/tile';
3-
import { environment } from '#store/environment';
43
import { observer } from 'mobx-react';
54

65
@observer
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
export function getBounds(mappings) {
3+
let minX = mappings[0].left;
4+
let maxX = mappings[0].left + mappings[0].width * 8;
5+
let minY = mappings[0].top;
6+
let maxY = mappings[0].top + mappings[0].height * 8;
7+
8+
mappings.slice(1).forEach(({ top, left, width, height }) => {
9+
minX = Math.min(left, minX);
10+
minY = Math.min(top, minY);
11+
maxX = Math.max(left + width * 8, maxX);
12+
maxY = Math.max(top + height * 8, maxY);
13+
});
14+
15+
return { minX, maxX, minY, maxY };
16+
}
17+
18+
export function getCenter(mappings) {
19+
const { minX, maxX, minY, maxY } = getBounds(mappings);
20+
21+
return {
22+
x: (minX + maxX) / 2,
23+
y: (minY + maxY) / 2,
24+
};
25+
}

app/components/mappings/state/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { observable, computed, action, autorun, toJS } from 'mobx';
22
import { environment } from '#store/environment';
33
import clamp from 'lodash/clamp';
4-
import { getCenter } from '#util/get-center';
4+
import { getCenter } from './bounds';
55
import { placeNewMapping } from './place-new-mapping';
66
import { optimizeCurrentDPLCs } from './optimize-dplcs';
77
import { deleteUnusedTiles } from './delete-unused-tiles';

app/components/mappings/state/toggle-dplcs.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ export function toggleDPLCs() {
3131

3232
mappings.forEach((mapping) => {
3333
const tileSize = mapping.width * mapping.height;
34-
const existingIndex = newDPLCs.findIndex(({art, size}) => (
35-
art == mapping.art && size >= tileSize
36-
));
3734

3835
newDPLCs.push({
3936
art: mapping.art,

app/components/sprites/sprite.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import React, { Component } from 'react';
22
import { environment } from '#store/environment';
33
import { observer } from 'mobx-react';
44
import { Mapping } from '#components/mappings/mapping';
5+
import { getBounds } from '#components/mappings/state/bounds';
56
import SVARS from '!!sass-variables-loader!#styles/variables.scss';
67

8+
const { max, min, abs, floor } = Math;
9+
710
@observer
811
export class Sprite extends Component {
912

@@ -13,35 +16,42 @@ export class Sprite extends Component {
1316

1417
const { index, mappings, buffer } = this.props.data;
1518

19+
let extent = 25;
20+
if (mappings.length) {
21+
const { minX, minY, maxX, maxY } = getBounds(mappings);
22+
23+
extent = max(abs(minX), maxX, abs(minY), maxY);
24+
}
25+
26+
const scale = min(5, max(floor(100 / extent), 1));
27+
1628
return <div
1729
className="sprite"
1830
style={{
1931
border: `1px solid ${SVARS[currentSprite == index ? 'magenta' : 'blue']}`,
2032
}}
2133
>
22-
<div>
23-
<div className="index">
24-
0x{index.toString(16).toUpperCase()}
25-
</div>
26-
{!mappings.length && (
27-
<div className="blank">
28-
[BLANK]
29-
</div>
30-
)}
31-
<div>
32-
{mappings.slice(0).reverse().map((mapping, mappingIndex) => {
33-
return <div
34-
key={mappingIndex}
35-
style={{zIndex: mappingIndex}}
36-
>
37-
<Mapping
38-
data={mapping}
39-
tileBuffer={buffer}
40-
/>
41-
</div>;
42-
})}
43-
</div>
34+
<div className="index">
35+
0x{index.toString(16).toUpperCase()}
4436
</div>
37+
38+
{!mappings.length && (
39+
<div className="blank">
40+
[BLANK]
41+
</div>
42+
)}
43+
{mappings.slice(0).reverse().map((mapping, mappingIndex) => {
44+
return <div
45+
key={mappingIndex}
46+
style={{zIndex: mappingIndex}}
47+
>
48+
<Mapping
49+
scale={scale}
50+
data={mapping}
51+
tileBuffer={buffer}
52+
/>
53+
</div>;
54+
})}
4555
</div>;
4656
}
4757

app/util/get-center.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)