Skip to content

Commit

Permalink
remove destroy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ramseyball authored Oct 10, 2023
1 parent d86714f commit c7e5829
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 122 deletions.
50 changes: 4 additions & 46 deletions button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ namespace microcode {
this.onClick = opts.onClick
this.buildSprite()
}

destroy() {
if (this.icon) {
this.icon.destroy()
}
this.icon = undefined
}


public getIcon() {
return this.iconId
}
Expand All @@ -167,10 +160,6 @@ namespace microcode {
}

private buildSprite() {
if (this.icon) {
this.icon.destroy()
}
//if (this.text) { this.text.destroy(); }
this.icon = new Sprite({
parent: this,
img:
Expand All @@ -179,9 +168,6 @@ namespace microcode {
: this.iconId,
})
this.icon.xfrm.parent = this.xfrm
//this.icon.xfrm.localPos.x = borderLeft(this.style);
//this.icon.xfrm.localPos.y = borderTop(this.style);

// This isn't quite right, but it's close enough for now
this.bounds_ = Bounds.GrowXY(
this.icon.bounds,
Expand Down Expand Up @@ -220,46 +206,18 @@ namespace microcode {
}
}

hover(hov: boolean) {
/*
if (hov && this.text) { return; }
if (!hov && !this.text) { return; }
if (!this.label) { return; }
if (!this.visible()) { return; }
if (hov) {
this.text = textsprite.create(this.label, 1, 15);
this.text.setBorder(1, 15);
this.text.x = this.x;
this.text.y = this.y - this.height;
this.text.z = this.icon.z;
} else {
this.text.destroy();
this.text = undefined;
}
*/
}
hover(hov: boolean) { }

/* override */ update() {
/*
if (this.text) {
this.text.x = this.x;
this.text.y = this.y - this.height;
}
*/
}
update() { }

isOffScreenX(): boolean {
return this.icon.isOffScreenX()
}

/* override */ draw() {
draw() {
control.enablePerfCounter()
this.drawStyle()
this.drawIcon()
//const iconbounds = Bounds.Translate(this.icon.bounds, this.icon.xfrm.worldPos);
//iconbounds.drawRect(5);
//const mybounds = Bounds.Translate(this.bounds, this.xfrm.worldPos);
//mybounds.drawRect(14)
}

private drawIcon() {
Expand Down
1 change: 0 additions & 1 deletion component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace microcode {

export interface IComponent {
destroy: () => void
update: () => void
draw: () => void
}
Expand Down
6 changes: 1 addition & 5 deletions cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ namespace microcode {
return false
}

destroy() {
this.navigator = undefined
}

update() {
const currTimeMs = control.millis()
const elapsedTimeMs = currTimeMs - this.moveStartMs
Expand All @@ -126,7 +122,7 @@ namespace microcode {
this.cycle = currTimeMs % 1000 < 500 ? 1 : 0
}

/* override */ draw() {
draw() {
control.enablePerfCounter()
if (!this.visible) return

Expand Down
39 changes: 3 additions & 36 deletions editor.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
namespace microcode {
export class EditorButton extends Button {
constructor(
private editor: Editor,
opts: {
parent?: IPlaceable
style?: ButtonStyle
icon: string | Image
ariaId?: string
label?: string
x: number
y: number
onClick?: (button: Button) => void
}
) {
super(opts)
editor.changed()
}

destroy() {
this.editor.changed()
super.destroy()
}
}

const TOOLBAR_HEIGHT = 17
const TOOLBAR_MARGIN = 2
Expand Down Expand Up @@ -135,9 +112,6 @@ namespace microcode {
if (index < 0 || index >= this.progdef.pages.length) {
return
}
if (this.pageEditor) {
this.pageEditor.destroy()
}
this.currPage = index
this.pageBtn.setIcon(PAGE_IDS[this.currPage])
this.pageEditor = new PageEditor(
Expand Down Expand Up @@ -263,7 +237,7 @@ namespace microcode {
this.cursor = new Cursor()
this.picker = new Picker(this.cursor)
this.currPage = 0
this.diskBtn = new EditorButton(this, {
this.diskBtn = new Button({
parent: this.hudroot,
style: ButtonStyles.BorderedPurple,
icon: icondb.disk,
Expand All @@ -272,7 +246,7 @@ namespace microcode {
y: 8,
onClick: () => this.pickDiskSLot(),
})
this.connectBtn = new EditorButton(this, {
this.connectBtn = new Button({
parent: this.hudroot,
style: ButtonStyles.BorderedPurple,
icon: icondb.microbit_logo_btn,
Expand All @@ -281,7 +255,7 @@ namespace microcode {
y: 8,
onClick: () => connectJacdac(),
})
this.pageBtn = new EditorButton(this, {
this.pageBtn = new Button({
parent: this.hudroot,
style: ButtonStyles.BorderedPurple,
icon: PAGE_IDS[this.currPage],
Expand Down Expand Up @@ -549,11 +523,6 @@ namespace microcode {
this.layout()
}

destroy() {
this.ruleEditors.forEach(rule => rule.destroy())
this.ruleEditors = undefined
}

private ensureFinalEmptyRule() {
if (this.ruleEditors) {
this.trimRules()
Expand All @@ -576,7 +545,6 @@ namespace microcode {
}
let last = this.ruleEditors[this.ruleEditors.length - 1]
while (last.isEmpty()) {
last.destroy()
this.ruleEditors.pop()
this.pagedef.rules.pop()
if (!this.ruleEditors.length) {
Expand Down Expand Up @@ -631,7 +599,6 @@ namespace microcode {
const rule = this.ruleEditors[index]
this.pagedef.deleteRuleAt(index)
this.ruleEditors.splice(index, 1)
rule.destroy()
this.ruleEditors.forEach((rule, index) => (rule.index = index))
this.changed()
this.editor.saveAndCompileProgram()
Expand Down
13 changes: 1 addition & 12 deletions picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ namespace microcode {
this.xfrm.parent = picker.xfrm
}

public destroy() {
this.buttons.forEach(btn => btn.destroy())
this.buttons = undefined
this.opts = undefined
this.bounds = undefined
}

public layout(maxPerRow: number) {
const cell = new Bounds()
this.buttons.forEach(btn => cell.add(btn.bounds))
Expand Down Expand Up @@ -171,11 +164,7 @@ namespace microcode {
this.visible = false
this.navigator.clear()
this.cursor.restoreState(this.prevState)
this.groups.forEach(group => group.destroy())
if (this.deleteBtn) {
this.deleteBtn.destroy()
this.deleteBtn = undefined
}
this.deleteBtn = undefined
this.groups = []
if (this.onHide) {
this.onHide()
Expand Down
26 changes: 7 additions & 19 deletions ruleeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace microcode {
) {
this.xfrm_ = new Affine()
this.xfrm_.parent = page.xfrm
this.handleBtn = new EditorButton(editor, {
this.handleBtn = new Button({
parent: this,
icon: "rule_handle",
ariaId: "rule",
Expand All @@ -51,7 +51,6 @@ namespace microcode {
}

private destroyWhenInsertButton() {
if (this.whenInsertBtn) this.whenInsertBtn.destroy()
this.whenInsertBtn = undefined
}

Expand All @@ -61,7 +60,7 @@ namespace microcode {
this.getSuggestions("filters", this.ruledef["filters"].length)
.length
) {
this.whenInsertBtn = new EditorButton(this.editor, {
this.whenInsertBtn = new Button({
parent: this,
style: ButtonStyles.Transparent,
icon: "when_insertion_point",
Expand All @@ -79,7 +78,6 @@ namespace microcode {
}

private destroyDoInsertButton() {
if (this.doInsertBtn) this.doInsertBtn.destroy()
this.doInsertBtn = undefined
}

Expand All @@ -91,7 +89,7 @@ namespace microcode {
this.ruledef["modifiers"].length
).length
) {
this.doInsertBtn = new EditorButton(this.editor, {
this.doInsertBtn = new Button({
parent: this,
style: ButtonStyles.Transparent,
icon: "do_insertion_point",
Expand All @@ -108,21 +106,10 @@ namespace microcode {
}
}

destroy() {
this.destroyProgramTiles()
this.handleBtn.destroy()
this.destroyWhenInsertButton()
this.destroyDoInsertButton()
this.handleBtn = undefined
this.whenInsertBtn = undefined
this.doInsertBtn = undefined
}

private destroyProgramTiles() {
let changed = false
repNames.forEach(name => {
if (this.ruleButtons[name].length) {
this.ruleButtons[name].forEach(btn => btn.destroy())
this.ruleButtons[name] = []
changed = true
}
Expand All @@ -137,7 +124,7 @@ namespace microcode {
repNames.forEach(name => {
const tiles = rule[name]
tiles.forEach((tile, index) => {
const button = new EditorButton(this.editor, {
const button = new Button({
parent: this,
style: tile.buttonStyle(),
icon: tile.getIcon(),
Expand All @@ -153,7 +140,7 @@ namespace microcode {
(sensor.jdKind == JdKind.Radio && sensor.tid != TID_SENSOR_LINE) ||
sensor.jdKind == JdKind.Variable
) {
const plus = new EditorButton(this.editor, {
const plus = new Button({
parent: this,
style: tile.buttonStyle(),
icon: "arith_equals",
Expand All @@ -173,7 +160,7 @@ namespace microcode {
tiles[index + 1].jdKind == JdKind.Variable ||
tiles[index + 1].jdKind == JdKind.RandomToss)
) {
const plus = new EditorButton(this.editor, {
const plus = new Button({
parent: this,
style: tile.buttonStyle(),
icon: "arith_plus",
Expand Down Expand Up @@ -388,6 +375,7 @@ namespace microcode {
}

public addToNavigator() {
// TODO: can this be done lazily instead?
const btns: Button[] = []
btns.push(this.handleBtn)
this.ruleButtons.sensors.forEach(b => btns.push(b))
Expand Down
3 changes: 0 additions & 3 deletions sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ namespace microcode {
this.image = opts.img
}

destroy() {
this.image = undefined
}
update() { }

public setImage(img: Image) {
Expand Down

0 comments on commit c7e5829

Please sign in to comment.