Skip to content

Commit 19f5e9e

Browse files
committed
fixed some dplc loading issues
1 parent 43c0eb2 commit 19f5e9e

File tree

8 files changed

+102
-33
lines changed

8 files changed

+102
-33
lines changed

app/components/file/file-object.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ export const FileObject = observer(({ obj }) => {
102102
const mappings = script.readMappings(buffer);
103103
if (mappings.error) throw mappings.error;
104104
environment.mappings.replace(mappings.sprites);
105+
if (
106+
obj.dplcs.enabled &&
107+
environment.dplcs.length < mappings.sprites.length
108+
) {
109+
const qty = mappings.sprites.length - environment.dplcs.length;
110+
for (let i = 0; i < qty; i++) {
111+
environment.dplcs.push([]);
112+
}
113+
}
105114
});
106115
}
107116

app/components/mappings/raw-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class RawEditor extends Component {
283283
<SortableDPLCList
284284
axis="y"
285285
lockAxis="y"
286-
items={dplcs}
286+
items={dplcs || []}
287287
lockToContainerEdges={true}
288288
useDragHandle={true}
289289
onSortEnd={this.onSortEndDPLC}

app/components/mappings/selection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Selection extends Component {
4141
class SelectionLayer extends Component {
4242
render() {
4343
const { extra, color, opacity, all, ...otherProps } = this.props;
44-
const { buffer, index, mappings } = environment.currentSprite;
44+
const { mappings } = environment.currentSprite;
4545
const { scale, x, y } = mappingState;
4646

4747
return <g {...otherProps}>

app/formats/scripts/debug.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
2-
import { observable, action, toJS, computed, runInAction, autorun } from 'mobx';
2+
import { observable, action, toJS, computed, autorun } from 'mobx';
33
import { observer } from 'mobx-react';
44
import { render } from 'react-dom';
55
import util from 'util';
66
import { Button } from '#ui';
7+
import { environment } from '#store/environment';
78

89
const inspect = (obj) => util.inspect(toJS(obj));
910

@@ -36,10 +37,14 @@ autorun(
3637
);
3738

3839
export const logger = (...args) => {
39-
log.msg(...args);
40+
log.enabled && log.msg(...args);
4041
};
4142

42-
window.log = log;
43+
Object.defineProperty(window, 'log', {
44+
get() {
45+
log.enabled = true;
46+
},
47+
});
4348

4449
const Debug = observer(function () {
4550
return (
@@ -60,26 +65,56 @@ const Debug = observer(function () {
6065
top: 0,
6166
left: 0,
6267
zIndex: 10,
68+
resize: 'both',
6369
}}
6470
>
6571
<div>
6672
<Button
67-
color="green"
73+
color="red"
6874
onClick={() => {
6975
log.enabled = false;
7076
}}
7177
>
7278
X
7379
</Button>
74-
<Button color="green" onClick={log.clear}>
80+
<Button color="blue" onClick={log.clear}>
7581
clear
7682
</Button>
83+
<Button
84+
color="yellow"
85+
onClick={() => {
86+
logger(environment.mappings);
87+
}}
88+
>
89+
mappings
90+
</Button>
91+
<Button
92+
color="magenta"
93+
onClick={() => {
94+
logger(environment.dplcs);
95+
}}
96+
>
97+
dplcs
98+
</Button>
99+
<Button
100+
onClick={() => {
101+
window.resetLayout();
102+
}}
103+
>
104+
clear layout
105+
</Button>
106+
<Button
107+
onClick={() => {
108+
window.resetStorage();
109+
}}
110+
>
111+
clear storage
112+
</Button>
77113
</div>
78114
<pre>{log.output}</pre>
79115
</div>
80116
)
81117
);
82118
});
83119

84-
__DEV__ &&
85-
render(<Debug />, document.body.appendChild(document.createElement('div')));
120+
render(<Debug />, document.body.appendChild(document.createElement('div')));

app/formats/scripts/run-script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ export default catchFunc((file) => {
161161
const sprites = [];
162162
const spritesAddr = {};
163163
sectionList.forEach(([readFrame], i) => {
164-
logger(`---section `, i);
164+
logger(`|> section `, i);
165165
read: for (let spriteIndex = 0; spriteIndex < readLimit; spriteIndex++) {
166-
logger(`--sprite ${spriteIndex.toString(16)} `);
166+
logger(`| sprite ${spriteIndex.toString(16)} `);
167167
const sprite = [];
168168
const ref = { global };
169169
spritesAddr[cursor] = sprite;
170170
const readMapping = readFrame(spriteIndex);
171171
if (readMapping) {
172172
logger('read mapping');
173173
for (let frameIndex = 0; frameIndex < readLimit; frameIndex++) {
174-
logger(`-frame ${frameIndex.toString(16)} `);
174+
logger(`.frame ${frameIndex.toString(16)} `);
175175
const mapping = {};
176176
const param = {
177177
mapping,

app/store/environment.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,56 @@ class Environment {
4040

4141
@computed get sprites() {
4242
return this.mappings.map((mappingList, index) => {
43-
let buffer = [];
44-
45-
const dplcsAvailable = this.config.dplcsEnabled && this.dplcs.length > index;
46-
47-
if (dplcsAvailable) {
43+
if (this.config.dplcsEnabled && this.dplcs.length > index) {
44+
const buffer = [];
4845
this.dplcs[index].forEach(({art, size}) => {
4946
Array.from({length: size}, (_, i) => {
5047
if (this.tiles.length <= art + i) {
5148
buffer.push([]);
52-
}
53-
else {
49+
} else {
5450
buffer.push(this.tiles[art + i]);
5551
}
5652
});
5753
});
54+
return {
55+
index,
56+
buffer,
57+
mappings: mappingList,
58+
dplcs: this.dplcs[index],
59+
};
60+
} else {
61+
return {
62+
index,
63+
buffer: this.tiles,
64+
mappings: mappingList,
65+
};
5866
}
59-
else {
60-
buffer = this.tiles;
61-
}
6267

63-
return {
64-
index, buffer,
65-
mappings: mappingList,
66-
dplcs: dplcsAvailable && this.dplcs[index],
67-
};
68+
69+
// let buffer = [];
70+
71+
// const dplcsAvailable = this.config.dplcsEnabled && this.dplcs.length > index;
72+
73+
// if (dplcsAvailable) {
74+
// this.dplcs[index].forEach(({art, size}) => {
75+
// Array.from({length: size}, (_, i) => {
76+
// if (this.tiles.length <= art + i) {
77+
// buffer.push([]);
78+
// } else {
79+
// buffer.push(this.tiles[art + i]);
80+
// }
81+
// });
82+
// });
83+
// }
84+
// else {
85+
// buffer = this.tiles;
86+
// }
87+
88+
// return {
89+
// index, buffer,
90+
// mappings: mappingList,
91+
// dplcs: dplcsAvailable && this.dplcs[index],
92+
// };
6893
});
6994
}
7095

@@ -78,7 +103,7 @@ class Environment {
78103
const { config: { dplcsEnabled }, currentSprite: { mappings, dplcs } } = environment;
79104
let activeTiles = [];
80105

81-
const objs = (dplcsEnabled ? dplcs : mappings);
106+
const objs = (dplcsEnabled && dplcs ? dplcs : mappings);
82107

83108
if (!objs.length) return [];
84109

scripts/Sonic 3&K Object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flex2 Mapping Definition - Sonic 3 Objects
1+
// Flex2 Mapping Definition - Sonic 3&K Objects
22

33
const {
44
mappings,
@@ -46,7 +46,7 @@ mappings([
4646
write(2, mapping.palette);
4747
write(1, mapping.vflip);
4848
write(1, mapping.hflip);
49-
write(11, mapping.offset);
49+
write(11, mapping.art);
5050
// left
5151
write(dc.w, mapping.left);
5252
};

scripts/Sonic 3&K Player.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ dplcs([
5959
[
6060
() => {
6161
const quantity = read(dc.w);
62-
return (({ mapping }, frameIndex) => {
62+
return quantity > 0 && (({ mapping }, frameIndex) => {
6363
mapping.size = read(nybble) + 1;
6464
mapping.art = read(nybble * 3);
65-
if (frameIndex === quantity) return endFrame;
65+
if (frameIndex + 1 === quantity) return endFrame;
6666
});
6767
},
6868
({ sprite }) => {
69-
write(dc.w, sprite.length - 1);
69+
write(dc.w, sprite.length);
7070
return ({ mapping }) => {
7171
write(nybble, mapping.size - 1);
7272
write(nybble * 3, mapping.art);

0 commit comments

Comments
 (0)