@@ -27,6 +27,22 @@ export interface MagicBallState {
2727 maxBounces : number ;
2828}
2929
30+ interface ActorPhysicsState {
31+ position : THREE . Vector3 ;
32+ orientation : THREE . Quaternion ;
33+ temp : {
34+ position : THREE . Vector3 ;
35+ destination : THREE . Vector3 ;
36+ angle : number ;
37+ destAngle : number ;
38+ doorPosition ?: [ number , number , number ] ;
39+ } ;
40+ carried : {
41+ position : THREE . Vector3 ;
42+ orientation : THREE . Quaternion ;
43+ } ;
44+ }
45+
3046export interface HeroState {
3147 behaviour : number ;
3248 prevBehaviour : number ;
@@ -45,12 +61,17 @@ export interface HeroState {
4561 magicball : MagicBallState ;
4662 handStrength : number ;
4763 lastValidPosTime : number ;
48- position : THREE . Vector3 ;
64+ physics : ActorPhysicsState ;
4965 animState ?: AnimStateJSON ;
5066}
5167
68+ interface SceneState {
69+ index : number ;
70+ }
71+
5272export interface GameState {
5373 config : GameConfig ;
74+ scene : SceneState ;
5475 hero : HeroState ;
5576 // The actor index who is currently talking.
5677 actorTalking : number ;
@@ -73,6 +94,9 @@ export function createGameState(): GameState {
7394 ambienceVolume : 0.2 ,
7495 positionalAudio : getParams ( ) . audio3d ,
7596 } , getLanguageConfig ( ) ) ,
97+ scene : {
98+ index : 0 ,
99+ } ,
76100 hero : {
77101 behaviour : 0 ,
78102 prevBehaviour : 0 ,
@@ -87,12 +111,12 @@ export function createGameState(): GameState {
87111 clover : { boxes : 2 , leafs : 1 } ,
88112 magicball : null ,
89113 handStrength : 5 , // LVL_0
90- position : null ,
91114 lastValidPosTime : 0 ,
92115 animState : null ,
93116 inventorySlot : 0 ,
94117 usingItemId : - 1 ,
95118 equippedItemId : - 1 ,
119+ physics : null ,
96120 } ,
97121 actorTalking : - 1 ,
98122 flags : {
@@ -101,7 +125,7 @@ export function createGameState(): GameState {
101125 holomap : createHolomapFlags ( )
102126 } ,
103127 save ( hero : Actor ) {
104- this . hero . position = hero . physics . position ;
128+ this . hero . physics = hero . physics ;
105129 this . hero . animState = hero . animState . toJSON ( ) ;
106130 return JSON . stringify ( omit ( this , [ 'save' , 'load' , 'config' ] ) ) ;
107131 } ,
@@ -110,9 +134,45 @@ export function createGameState(): GameState {
110134 if ( ! state ) {
111135 return ;
112136 }
113- hero . physics . position . x = state . hero . position . x ;
114- hero . physics . position . y = state . hero . position . y ;
115- hero . physics . position . z = state . hero . position . z ;
137+ hero . physics . position = new THREE . Vector3 (
138+ state . hero . physics . position . x ,
139+ state . hero . physics . position . y ,
140+ state . hero . physics . position . z ,
141+ ) ;
142+ hero . physics . orientation = new THREE . Quaternion (
143+ state . hero . physics . orientation . x ,
144+ state . hero . physics . orientation . y ,
145+ state . hero . physics . orientation . z ,
146+ state . hero . physics . orientation . w
147+ ) ;
148+ // hero.threeObject.rotation.setFromQuaternion(state.hero.physics.orientation);
149+ // hero.physics.temp.position = new THREE.Vector3(
150+ // state.hero.physics.temp.position?.x || 0,
151+ // state.hero.physics.temp.position?.y || 0,
152+ // state.hero.physics.temp.position?.z || 0
153+ // );
154+ // hero.physics.temp.destination = new THREE.Vector3(
155+ // state.hero.physics.temp.destination?.x || 0,
156+ // state.hero.physics.temp.destination?.y || 0,
157+ // state.hero.physics.temp.destination?.z || 0
158+ // );
159+ hero . physics . temp . angle = state . hero . physics . temp . angle ;
160+ hero . physics . temp . destAngle = state . hero . physics . temp . angle ; // void turning
161+ hero . state . isTurning = true ;
162+ // if (state.hero.physics.temp.doorPosition) {
163+ // hero.physics.temp.doorPosition = [
164+ // state.hero.physics.temp.doorPosition[0],
165+ // state.hero.physics.temp.doorPosition[1],
166+ // state.hero.physics.temp.doorPosition[2]
167+ // ];
168+ // } else {
169+ // hero.physics.temp.doorPosition = null;
170+ // }
171+ hero . physics . carried . position = new THREE . Vector3 (
172+ state . hero . physics . carried . position . x ,
173+ state . hero . physics . carried . position . y ,
174+ state . hero . physics . carried . position . z
175+ ) ;
116176 // Merge the current animState with the saved one, overwritting
117177 // things like the currentFrame etc. to ensure we e.g. continue to
118178 // fly the jetpack if we drown whilst using it.
0 commit comments