Skip to content

Commit

Permalink
dispose copies children
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Dec 3, 2022
1 parent 0ecf34e commit 87c4058
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class Statistics extends Play {
h: 920,
panels
})

}
}

Expand Down Expand Up @@ -320,8 +319,6 @@ class StatsGamesPlayed extends Play {
h: 0,
panels
})


}
}

Expand Down Expand Up @@ -891,6 +888,9 @@ class TabPanel extends Play {
batch.pop_matrix()
}

_dispose() {
this.data.panels.forEach(_ => _.dispose())
}

}

Expand Down Expand Up @@ -1079,8 +1079,8 @@ class SceneTransition extends Play {
this.target = Target.create(Game.width, Game.height)
this.mask_target = Target.create(Game.width, Game.height)

//this.current = this._make(MainMenu, Vec2.zero, {})
this.current = this._make(Statistics, Vec2.zero, {})
this.current = this._make(MainMenu, Vec2.zero, {})
//this.current = this._make(Statistics, Vec2.zero, {})

transition.set_matrix(Mat3x2.create_scale_v(Game.v_screen))

Expand Down
9 changes: 4 additions & 5 deletions src/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ export abstract class Play {

dispose() {

if (this.parent) {
this.parent.objects.splice(this.parent.objects.indexOf(this), 1)
}
this.objects.forEach(_ => _.dispose())
this.objects.slice(0).forEach(_ => _.dispose())
this._dispose()

this._disposes.forEach(_ => _())

if (this.parent) {
this.parent.objects.splice(this.parent.objects.indexOf(this), 1)
}
}

_init() {}
Expand Down
15 changes: 13 additions & 2 deletions src/scrollable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,20 @@ class InfiniteLongList extends Play {
return Math.round(- this._viewport_y / this.item_height)
}

get height() {
return this.runway.i_bottom * this.item_height
}

item_height!: number
dummy_item!: Play

get item_height() {
return (this.dummy_item as any).height
}
runway!: Runway<any, any>

_init() {

this.item_height = (this._make(this.data.ItemContent, Vec2.make(0, 0), this.data.items[0]) as any).height
this.dummy_item = (this._make(this.data.ItemContent, Vec2.make(0, 0), this.data.items[0]) as any)

const on_make = (item: any, i: number) =>
this.make(this.data.ItemContent, Vec2.make(0, i * this.item_height), item)
Expand All @@ -307,6 +314,10 @@ class InfiniteLongList extends Play {
this.position.y = this._viewport_y
}

_dispose() {
this.dummy_item.dispose()
}

}

type ScrollableContentData = {
Expand Down

0 comments on commit 87c4058

Please sign in to comment.