Skip to content

Commit 74117cf

Browse files
committed
loading and saving
1 parent 2e0ae72 commit 74117cf

8 files changed

Lines changed: 91 additions & 9 deletions

File tree

modules/components/project/object.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react';
2+
import { extname } from 'path';
23
import { observer } from 'mobx-react';
34
import {Collapse} from 'react-collapse';
45
import { Item, Input, File, Select, Editor } from '#ui';
@@ -130,6 +131,15 @@ export class ObjectConfig extends Component {
130131
/>
131132
</div>
132133
)}
134+
{extname(obj.mappings.path) == '.asm' && (
135+
<Input
136+
containerClass="row-input"
137+
label="Label"
138+
store={obj.mappings}
139+
accessor="label"
140+
placeholder="Label Name"
141+
/>
142+
)}
133143
<File
134144
store={obj.mappings}
135145
accessor="path"
@@ -182,6 +192,15 @@ export class ObjectConfig extends Component {
182192
/>
183193
</div>
184194
)}
195+
{extname(obj.dplcs.path) == '.asm' && (
196+
<Input
197+
containerClass="row-input"
198+
label="Label"
199+
store={obj.dplcs}
200+
accessor="label"
201+
placeholder="Label Name"
202+
/>
203+
)}
185204
<File
186205
store={obj.dplcs}
187206
accessor="path"

modules/components/ui/input/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ export class Input extends Component {
5353
assert,
5454
isNumber,
5555
onChange,
56+
containerClass,
5657
...otherProps,
5758
} = this.props;
5859

59-
return <div>
60+
return <div className={containerClass}>
6061
{label && <span>
6162
{label}
6263
&emsp;

modules/formats/asm.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import chunk from 'lodash/chunk';
2+
13
const sizeLookup = {
24
'b': 1,
35
'w': 2,
@@ -76,6 +78,58 @@ export function asmToBin(buffer) {
7678
return bytes;
7779
}
7880

79-
export function stuffToAsm(headers, frames, name) {
80-
return '';
81+
export function stuffToAsm(frames, name, isMapping = false) {
82+
// get real mapping name
83+
const startLabel = name.replace(/[^\w]/g, '');
84+
85+
let output = `; ${'='.repeat(80)}
86+
; Sprite ${isMapping?'Mappings' : 'DPLCs'} - generated by Flex 2 ${new Date()}
87+
; ${'='.repeat(80)}
88+
89+
`;
90+
if (startLabel) {
91+
output += startLabel + ':\n';
92+
}
93+
94+
let mainLabel = startLabel || 'DATA' + Math.random().toString(36).slice(2).toUpperCase();
95+
96+
let dataOutput = '';
97+
let labels = [];
98+
99+
frames.forEach((arrays, index) => {
100+
let label;
101+
if (arrays.length == 0) {
102+
label = 0;
103+
}
104+
else {
105+
label = `${mainLabel}_${index.toString(16).toUpperCase()}`;
106+
const [header, ...data] = arrays;
107+
// header
108+
dataOutput += `${label}: dc.b ${to68kByteStr(header)}\n`;
109+
// pieces
110+
data.forEach((piece) => {
111+
piece.forEach((datum) => {
112+
dataOutput += `\tdc.b ${to68kByteStr(datum)}\n`;
113+
});
114+
});
115+
}
116+
labels.push(label);
117+
});
118+
119+
dataOutput += '\teven';
120+
121+
// draw headers
122+
chunk(labels, 2)
123+
.forEach((words) => {
124+
output += `\tdc.w ${words.map((word) => (
125+
word == 0 ? '$0' : `${word}-${mainLabel}`
126+
)).join`, `}\n`;
127+
});
128+
129+
output += dataOutput;
130+
return output;
131+
}
132+
133+
function to68kByteStr(arr) {
134+
return arr.map((d) => '$' + d.toString(16).toUpperCase()).join`, `;
81135
}

modules/formats/dplc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function DPLCsToBuffer(dplcs, format) {
109109

110110
return {
111111
chunk: new Buffer(Uint8Array.from(bytes)),
112-
headers: headerWords,
113112
frames: framesArray,
114113
};
115114

modules/formats/mapping.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ export function mappingsToBuffer(mappings, format) {
172172

173173
return {
174174
chunk: new Buffer(Uint8Array.from(bytes)),
175-
headers: headerWords,
176175
frames: framesArray,
177176
};
178177

modules/store/environment.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ class Environment {
198198
const mappingPath = workspace.absolutePath(obj.mappings.path);
199199
const isAsm = extname(obj.mappings.path) == '.asm';
200200

201-
const { chunk, headers, frames } = mappingsToBuffer(this.mappings, obj.mappingDefinition);
202-
const out = isAsm ? stuffToAsm(headers, frames, obj.name) : chunk;
201+
const { chunk, frames } = mappingsToBuffer(this.mappings, obj.mappingDefinition);
202+
const out = isAsm ? stuffToAsm(frames, obj.mappings.label, true) : chunk;
203203
writeFile(mappingPath, out, (err, success) => {
204204
err && errorMsg('Error Saving Mappings', err.message);
205205
});
@@ -210,8 +210,8 @@ class Environment {
210210
const dplcPath = workspace.absolutePath(obj.dplcs.path);
211211
const isAsm = extname(obj.dplcs.path) == '.asm';
212212

213-
const { chunk, headers, frames } = DPLCsToBuffer(this.dplcs, obj.dplcDefinition);
214-
const out = isAsm ? stuffToAsm(headers, frames, obj.name) : chunk;
213+
const { chunk, frames } = DPLCsToBuffer(this.dplcs, obj.dplcDefinition);
214+
const out = isAsm ? stuffToAsm(frames, obj.dplcs.label) : chunk;
215215
writeFile(dplcPath, out, (err, success) => {
216216
err && errorMsg('Error Saving DPLCs', err.message);
217217
});

modules/store/objectdef.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export class ObjectDef {
1414
path: '',
1515
format: 'Sonic 1',
1616
customDefinition: '',
17+
label: '',
1718
};
1819
@observable dplcs = {
1920
enabled: false,
2021
path: '',
2122
format: 'Sonic 1',
2223
customDefinition: '',
24+
label: '',
2325
};
2426

2527
@computed get key() {

styles/components/project-config.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
margin: 30px 0 40px 0;
1111
}
1212

13+
.row-input {
14+
@extend .row;
15+
padding-bottom: 15px;
16+
input {
17+
width: 147.5px;
18+
}
19+
}
20+
1321
.panel {
1422
margin: 10px 0;
1523
padding: 5px 5px 0 5px;

0 commit comments

Comments
 (0)