Skip to content

Commit 3a09e72

Browse files
committed
made StateHandler use a list instead of a dict, since dicts aren't sorted. also made it possible to give it just a color and it will still make a background entity and tint it that color.
1 parent 8349f07 commit 3a09e72

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

taptapir.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,16 +1003,28 @@ function Canvas(options) {
10031003
return e
10041004
}
10051005

1006-
function Scene(options) {
1007-
settings = {visible_self:false, on_enter:null, on_exit:null, enabled:false, texture:null}
1008-
for (const [key, value] of Object.entries(options)) {
1006+
function Scene(input) {
1007+
settings = {parent:scene, visible_self:false, on_enter:null, on_exit:null, enabled:false, texture:null}
1008+
_bg_color = input.color
1009+
input.color = null
1010+
1011+
for (const [key, value] of Object.entries(input)) {
10091012
settings[key] = value
10101013
}
1011-
name = settings['name']
1014+
10121015
_entity = new Entity(settings)
1013-
if (settings['texture']) {
1014-
_entity.bg = new Entity({parent:_entity, scale_x:asp_x*camera.fov, scale_y:1/asp_y*camera.fov, texture:settings['texture']})
1016+
1017+
if (input.texture || _bg_color) {
1018+
_entity.bg = new Entity({parent:_entity, scale_x:asp_x*camera.fov, scale_y:1/asp_y*camera.fov})
1019+
if (input.texture) {
1020+
_entity.bg.texture = input.texture
1021+
}
1022+
if (_bg_color) {
1023+
_entity.bg.color = _bg_color
1024+
}
10151025
}
1026+
scene_handler.states.push(_entity)
1027+
10161028
if (AUTOPARENT_TO_SCENE) {
10171029
LAST_SCENE = _entity
10181030
// print('set LASTSCENE to:', _entity.name)
@@ -1021,17 +1033,19 @@ function Scene(options) {
10211033
}
10221034
class StateHandler {
10231035
constructor (options) {
1024-
let settings = {states:{}, fade:false, fade_in_duration:.2, fade_out_duration:1}
1036+
let settings = {states:[], fade:false, fade_in_duration:.5, fade_out_duration:1}
10251037
for (const [key, value] of Object.entries(options)) {
10261038
settings[key] = value
10271039
}
1028-
1040+
if (!camera.overlay) {
10291041
camera.overlay = new Entity({parent:camera, name:'overlay', color:color.black, alpha:0, z:-99, scale:[1.1,aspect_ratio*1.1]})
1042+
// print('make new overlay')
1043+
}
10301044
this.states = settings['states']
10311045
this.fade = settings['fade']
10321046
this.fade_in_duration = settings['fade_in_duration']
10331047
this.fade_out_duration = settings['fade_out_duration']
1034-
this.state = Object.keys(this.states)[0]
1048+
this.state = this.states[0]
10351049
}
10361050

10371051
get state() {return this._state}
@@ -1052,9 +1066,8 @@ class StateHandler {
10521066
if (this._state === value) {
10531067
return
10541068
}
1055-
for (const [key, entity] of Object.entries(this.states)) {
1056-
// print('----', key, value)
1057-
if (key == value || value == entity) {
1069+
for (let entity of this.states) {
1070+
if (value === entity || value === entity.name) {
10581071
entity.enabled = true
10591072
if (entity.on_enter) {
10601073
entity.on_enter()
@@ -1074,12 +1087,12 @@ class StateHandler {
10741087

10751088
scene_handler = new StateHandler({fade:true})
10761089

1077-
function goto_scene(scene_name, fade=True) {
1090+
function goto_scene(scene, fade=True) {
10781091
if (!fade) {
1079-
scene_handler.hard_state = scene_name
1092+
scene_handler.hard_state = scene
10801093
return
10811094
}
1082-
scene_handler.state = scene_name
1095+
scene_handler.state = scene
10831096
}
10841097

10851098
class HealthBar extends Entity {

0 commit comments

Comments
 (0)