Skip to content

Commit

Permalink
more mods
Browse files Browse the repository at this point in the history
  • Loading branch information
ramseyball authored Oct 10, 2023
1 parent c7e5829 commit 777b0fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
17 changes: 7 additions & 10 deletions button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ namespace microcode {
export class Button implements IComponent, ISizable, IPlaceable {
private xfrm_: Affine
private icon: Sprite
//private text: TextSprite;
private style: ButtonStyle
private iconId: string | Image
private _ariaId: string
public onClick?: (button: Button) => void
private bounds_: Bounds

//% blockCombine block="xfrm" callInDebugger
public get xfrm() {
Expand Down Expand Up @@ -112,7 +110,12 @@ namespace microcode {

public get bounds() {
// Returns bounds in local space
return this.bounds_
// This isn't quite right, but it's close enough for now
return Bounds.GrowXY(
this.icon.bounds,
borderLeft(this.style),
borderTop(this.style)
)
}

public get rootXfrm(): Affine {
Expand Down Expand Up @@ -142,7 +145,7 @@ namespace microcode {
this.onClick = opts.onClick
this.buildSprite()
}

public getIcon() {
return this.iconId
}
Expand All @@ -168,12 +171,6 @@ namespace microcode {
: this.iconId,
})
this.icon.xfrm.parent = this.xfrm
// This isn't quite right, but it's close enough for now
this.bounds_ = Bounds.GrowXY(
this.icon.bounds,
borderLeft(this.style),
borderTop(this.style)
)
}

public occlusions(bounds: Bounds) {
Expand Down
6 changes: 3 additions & 3 deletions editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ namespace microcode {
public addToNavigator() {
this.ruleEditors.forEach(rule => {
this.editor.navigator.addRule(rule.ruledef)
rule.addToNavigator()
this.editor.addButtons(rule.getRuleButtons())
})
}

Expand Down Expand Up @@ -622,11 +622,11 @@ namespace microcode {
}
}

/* override */ update() {
update() {
this.ruleEditors.forEach(rule => rule.update())
}

/* override */ draw() {
draw() {
control.enablePerfCounter()
this.ruleEditors.forEach(rule => rule.draw())
}
Expand Down
5 changes: 3 additions & 2 deletions ruleeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace microcode {
changed = true
}
})
// TODO: do we really need this?
if (changed) this.editor.changed()
}

Expand Down Expand Up @@ -374,7 +375,7 @@ namespace microcode {
return Language.getTileSuggestions(this.ruledef, name, index)
}

public addToNavigator() {
public getRuleButtons() {
// TODO: can this be done lazily instead?
const btns: Button[] = []
btns.push(this.handleBtn)
Expand All @@ -388,7 +389,7 @@ namespace microcode {

if (this.doInsertBtn) btns.push(this.doInsertBtn)

this.editor.addButtons(btns)
return btns
}

public isEmpty() {
Expand Down
26 changes: 0 additions & 26 deletions sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,17 @@ namespace microcode {
p.x - (this.width >> 1) > Screen.RIGHT_EDGE
)
}
/*
public isOffScreen(): boolean {
const p = this.xfrm.worldPos
return (
p.x + (this.width >> 1) < Screen.LEFT_EDGE ||
p.y + (this.height >> 1) < Screen.TOP_EDGE ||
p.x - (this.width >> 1) > Screen.RIGHT_EDGE ||
p.y - (this.height >> 1) > Screen.BOTTOM_EDGE
)
}
public isClipped(): boolean {
const p = this.xfrm.worldPos
return (
p.x - (this.width >> 1) < Screen.LEFT_EDGE ||
p.y - (this.height >> 1) < Screen.TOP_EDGE ||
p.x + (this.width >> 1) > Screen.RIGHT_EDGE ||
p.y + (this.height >> 1) > Screen.BOTTOM_EDGE
)
}*/
draw() {
control.enablePerfCounter()
if (this.invisible) {
return
}

// perf: this is not really required anymore as rules are clipped vertically and tiles horizontally
// if (this.isOffScreen()) {
// return
//}

Screen.drawTransparentImageXfrm(
this.xfrm,
this.image,
-(this.image.width >> 1),
-(this.image.height >> 1)
)
//this.hitbox.drawRect(15);
}
}

Expand Down

0 comments on commit 777b0fa

Please sign in to comment.