Skip to content

Commit 94e1b16

Browse files
committed
done unparsing
1 parent 280f7ce commit 94e1b16

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

fieldeditors.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace microcode {
3232
fromBuffer(buf: BufferReader): any {
3333
return undefined
3434
}
35-
toText(field: any): string {
35+
toString(field: any): string {
3636
return ""
3737
}
38-
fromText(text: string): any {
38+
fromString(text: string): any {
3939
return undefined
4040
}
4141
}
@@ -99,10 +99,10 @@ namespace microcode {
9999
const str = buf.readString()
100100
return { num: str }
101101
}
102-
toText(field: BoxedNumAsStr) {
102+
toString(field: BoxedNumAsStr) {
103103
return field.num
104104
}
105-
fromText(txt: string) {
105+
fromString(txt: string) {
106106
return { num: txt }
107107
}
108108
}
@@ -182,7 +182,7 @@ namespace microcode {
182182
}
183183
return img
184184
}
185-
toText(img: Bitmap) {
185+
toString(img: Bitmap) {
186186
let ret = ""
187187
for (let row = 0; row < 5; row++) {
188188
for (let col = 0; col < 5; col++) {
@@ -192,7 +192,7 @@ namespace microcode {
192192
}
193193
return ret
194194
}
195-
fromText(txt: string): Bitmap {
195+
fromString(txt: string): Bitmap {
196196
let ret = bitmaps.create(5, 5)
197197
let seq = txt.split(" \n")
198198
seq.forEach((s, i) => {
@@ -247,7 +247,7 @@ namespace microcode {
247247
let res = ""
248248
seq.forEach((note, index) => {
249249
if (note == "-") res += "."
250-
else res += noteNames.indexOf(note).toString
250+
else res += noteNames.indexOf(note).toString()
251251
})
252252
return { notes: res, tempo: 120 }
253253
}
@@ -308,10 +308,10 @@ namespace microcode {
308308
}
309309
return { tempo, notes }
310310
}
311-
toText(melody: Melody): string {
311+
toString(melody: Melody): string {
312312
return melodyToNotes(melody)
313313
}
314-
fromText(txt: string): Melody {
314+
fromString(txt: string): Melody {
315315
return notesToMelody(txt)
316316
}
317317
}

language.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,29 @@ namespace microcode {
279279
return defn
280280
}
281281

282-
// TODO: deal with field editors
283282
public toString() {
284283
const toToken = (tile: Tile) =>
285284
resolveTooltip("T" + getTid(tile)).replaceAll(" ", "-")
286-
return toToken(this.sensor) +
285+
const tileToString = (tile: Tile) => {
286+
const tok = toToken(tile)
287+
if (tile instanceof ModifierEditor) {
288+
const mod = tile as ModifierEditor
289+
return tok + `\n` + mod.fieldEditor.toString(mod.getField())
290+
}
291+
return tok
292+
}
293+
return (
294+
toToken(this.sensor) +
287295
" " +
288-
this.filters.map(toToken).join(" ") +
296+
this.filters.map(tileToString).join(" ") +
289297
" " +
290-
this.actuators.length
291-
? toToken(this.actuators[0]) +
298+
(this.actuators.length
299+
? toToken(this.actuators[0]) +
292300
" " +
293-
this.modifiers.map(toToken).join(" ")
294-
: ""
301+
this.modifiers.map(tileToString).join(" ")
302+
: "") +
303+
" EOR\n"
304+
)
295305
}
296306
}
297307

0 commit comments

Comments
 (0)