@@ -1003,16 +1003,28 @@ function Canvas(options) {
1003
1003
return e
1004
1004
}
1005
1005
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 ) ) {
1009
1012
settings [ key ] = value
1010
1013
}
1011
- name = settings [ 'name' ]
1014
+
1012
1015
_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
+ }
1015
1025
}
1026
+ scene_handler . states . push ( _entity )
1027
+
1016
1028
if ( AUTOPARENT_TO_SCENE ) {
1017
1029
LAST_SCENE = _entity
1018
1030
// print('set LASTSCENE to:', _entity.name)
@@ -1021,17 +1033,19 @@ function Scene(options) {
1021
1033
}
1022
1034
class StateHandler {
1023
1035
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 }
1025
1037
for ( const [ key , value ] of Object . entries ( options ) ) {
1026
1038
settings [ key ] = value
1027
1039
}
1028
-
1040
+ if ( ! camera . overlay ) {
1029
1041
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
+ }
1030
1044
this . states = settings [ 'states' ]
1031
1045
this . fade = settings [ 'fade' ]
1032
1046
this . fade_in_duration = settings [ 'fade_in_duration' ]
1033
1047
this . fade_out_duration = settings [ 'fade_out_duration' ]
1034
- this . state = Object . keys ( this . states ) [ 0 ]
1048
+ this . state = this . states [ 0 ]
1035
1049
}
1036
1050
1037
1051
get state ( ) { return this . _state }
@@ -1052,9 +1066,8 @@ class StateHandler {
1052
1066
if ( this . _state === value ) {
1053
1067
return
1054
1068
}
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 ) {
1058
1071
entity . enabled = true
1059
1072
if ( entity . on_enter ) {
1060
1073
entity . on_enter ( )
@@ -1074,12 +1087,12 @@ class StateHandler {
1074
1087
1075
1088
scene_handler = new StateHandler ( { fade :true } )
1076
1089
1077
- function goto_scene ( scene_name , fade = True ) {
1090
+ function goto_scene ( scene , fade = True ) {
1078
1091
if ( ! fade ) {
1079
- scene_handler . hard_state = scene_name
1092
+ scene_handler . hard_state = scene
1080
1093
return
1081
1094
}
1082
- scene_handler . state = scene_name
1095
+ scene_handler . state = scene
1083
1096
}
1084
1097
1085
1098
class HealthBar extends Entity {
0 commit comments