Skip to content

Commit

Permalink
feat: editboard should now work for main frame
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed Apr 24, 2024
1 parent 728b8a2 commit 48f39a5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
4 changes: 2 additions & 2 deletions zss/bios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ defaults to object typedef
@object name
@name ' object: scope is optional
' rest of object code goes here
' ie: after typing out @object:ripper
' ie: after typing out @object ripper
' you can now launch an objectedit for ripper

@terrain name
' rest of terrain code goes here
' ie: after typing out @terrain:endlesspit
' ie: after typing out @terrain endlesspit
' you can now launch a terrainedit for endlesspit

@charset name
Expand Down
2 changes: 0 additions & 2 deletions zss/bios/player.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@player

#all:doot

' create content
#book temp create

Expand Down
6 changes: 3 additions & 3 deletions zss/firmware/wordtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,15 @@ export function readkind(
return [undefined, index]
}

export function readkindname(kind: MAYBE<STR_KIND>): MAYBE_STRING {
export function readstrkindname(kind: MAYBE<STR_KIND>): MAYBE_STRING {
if (!isstrkind(kind)) {
return undefined
}
const [maybename] = kind
return maybename
}

export function readkindcolor(kind: MAYBE<STR_KIND>): MAYBE<COLOR> {
export function readstrkindcolor(kind: MAYBE<STR_KIND>): MAYBE<COLOR> {
if (!isstrkind(kind)) {
return undefined
}
Expand All @@ -490,7 +490,7 @@ export function readkindcolor(kind: MAYBE<STR_KIND>): MAYBE<COLOR> {
return ispresent(color) ? color : undefined
}

export function readkindbg(kind: MAYBE<STR_KIND>): MAYBE<COLOR> {
export function readstrkindbg(kind: MAYBE<STR_KIND>): MAYBE<COLOR> {
if (!isstrkind(kind)) {
return undefined
}
Expand Down
60 changes: 48 additions & 12 deletions zss/firmware/zzt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
INPUT_SHIFT,
} from 'zss/gadget/data/types'
import { clamp } from 'zss/mapping/number'
import { isnumber, ispresent, isstring } from 'zss/mapping/types'
import { MAYBE, isnumber, ispresent, isstring } from 'zss/mapping/types'
import { memoryreadbook, memoryreadchip, memoryreadframes } from 'zss/memory'
import {
listelementsbyattr,
Expand All @@ -23,9 +23,10 @@ import {
bookreadflag,
booksetflag,
bookboardobjectsafedelete,
bookboardelementreadname,
} from 'zss/memory/book'
import { editboard } from 'zss/memory/edit'
import { FRAME_TYPE } from 'zss/memory/frame'
import { FRAME_STATE, FRAME_TYPE } from 'zss/memory/frame'

import {
categoryconsts,
Expand All @@ -35,8 +36,11 @@ import {
readexpr,
readargs,
ARG_TYPE,
readkindname,
readstrkindname,
PT,
readstrkindcolor,
readstrkindbg,
ispt,
} from './wordtypes'

const STAT_NAMES = new Set([
Expand Down Expand Up @@ -259,11 +263,39 @@ export const ZZT_FIRMWARE = createfirmware({
ARG_TYPE.KIND,
])

const targetname = readkindname(target) ?? ''
const targetname = readstrkindname(target) ?? ''
const boardelements = listnamedelements(memory.board, targetname)
const targetelements = listelementsbykind(boardelements, target)

console.info({ targetname, boardelements, targetelements, into })
targetelements.forEach((element) => {
const kindname = readstrkindname(into)
if (bookboardelementreadname(memory.book, element) === kindname) {
const color = readstrkindcolor(into)
if (ispresent(color)) {
element.color = color
}
const bg = readstrkindbg(into)
if (ispresent(bg)) {
element.bg = bg
}
} else {
// delete object
if (ispresent(element.id)) {
bookboardobjectsafedelete(
memory.book,
memory.board,
element,
chip.timestamp(),
)
}
// create new element
if (ispt(element)) {
editboard(memory.book, memory.board, element, into)
}
}
})

// console.info({ targetelements, into })
return 0
})
.command('char', (chip, words) => {
Expand Down Expand Up @@ -391,19 +423,23 @@ export const ZZT_FIRMWARE = createfirmware({
ARG_TYPE.KIND,
])

// todo: can we put into view frames ?
let maybeframe: MAYBE<FRAME_STATE>
const frames = memoryreadframes(memory.board?.id ?? '')
switch (dir.frame) {
case 'edit': {
const frame = memoryreadframes(memory.board?.id ?? '').find(
(item) => item.type === FRAME_TYPE.EDIT,
)
const book = memoryreadbook(frame?.book ?? '') ?? memory.book
const board = bookreadboard(book, frame?.board ?? '')
editboard(book, board, dir, kind)
maybeframe = frames.find((item) => item.type === FRAME_TYPE.EDIT)
break
}
}

const maybebook = maybeframe
? memoryreadbook(maybeframe?.book ?? '')
: memory.book
const maybeboard = maybeframe
? bookreadboard(maybebook, maybeframe?.board ?? '')
: memory.board

editboard(maybebook, maybeboard, dir, kind)
return 0
})
// .command('restart' // this is handled by a built-in 0 label
Expand Down
12 changes: 6 additions & 6 deletions zss/memory/atomics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
PT,
STR_KIND,
ispt,
readkindbg,
readkindcolor,
readkindname,
readstrkindbg,
readstrkindcolor,
readstrkindname,
} from 'zss/firmware/wordtypes'
import { ispresent } from 'zss/mapping/types'

Expand Down Expand Up @@ -56,9 +56,9 @@ export function listelementsbykind(
elements: MAYBE_BOARD_ELEMENT[],
kind: STR_KIND,
): BOARD_ELEMENT[] {
const name = readkindname(kind)
const color = readkindcolor(kind)
const bg = readkindbg(kind)
const name = readstrkindname(kind)
const color = readstrkindcolor(kind)
const bg = readstrkindbg(kind)
return elements
.filter((element) => {
if (ispresent(name) && boardelementname(element) !== name) {
Expand Down
11 changes: 5 additions & 6 deletions zss/memory/edit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { STR_KIND } from 'zss/firmware/wordtypes'
import { PT, STR_KIND } from 'zss/firmware/wordtypes'
import { ispresent } from 'zss/mapping/types'

import {
BOARD_DIR,
MAYBE_BOARD,
boardelementapplycolor,
boardgetterrain,
Expand All @@ -14,7 +13,7 @@ import { MAYBE_BOOK, bookreadobject, bookreadterrain } from './book'
export function editboard(
book: MAYBE_BOOK,
board: MAYBE_BOARD,
dir: BOARD_DIR,
dest: PT,
kind: STR_KIND,
) {
if (!book || !board) {
Expand All @@ -24,13 +23,13 @@ export function editboard(
const [name, maybecolor] = kind
const maybeterrain = bookreadterrain(book, name)
if (ispresent(maybeterrain)) {
boardsetterrainfromkind(board, dir.x, dir.y, name)
boardelementapplycolor(boardgetterrain(board, dir.x, dir.y), maybecolor)
boardsetterrainfromkind(board, dest.x, dest.y, name)
boardelementapplycolor(boardgetterrain(board, dest.x, dest.y), maybecolor)
}

const maybeobject = bookreadobject(book, kind[0])
if (ispresent(maybeobject) && ispresent(maybeobject.name)) {
createboardobjectfromkind(board, dir.x, dir.y, maybeobject)
createboardobjectfromkind(board, dest.x, dest.y, maybeobject)
boardelementapplycolor(maybeobject, maybecolor)
}
}
2 changes: 1 addition & 1 deletion zss/memory/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MAYBE_STRING } from 'zss/mapping/types'

export enum FRAME_TYPE {
VIEW, // a view into book state
EDIT, // shared crdt backed book state + copy buffers
EDIT, // shared crdt backed book state + copy buffers ( maybe ?? really just need good undo/redo )
}

export type FRAME_STATE = {
Expand Down

0 comments on commit 48f39a5

Please sign in to comment.