@@ -76,8 +76,8 @@ module Netcode {
76
76
send ( "ident" , { name } ) ;
77
77
}
78
78
79
- function findObjectByPID ( pid : number ) : Obj | null {
80
- return _ . find ( gMap . getObjects ( ) , ( obj : Obj ) => obj . pid === pid ) || null ;
79
+ function findObjectByUID ( uid : number ) : Obj | null {
80
+ return _ . find ( gMap . getObjects ( ) , ( obj : Obj ) => obj . uid === uid ) || null ;
81
81
}
82
82
83
83
function setupCommonEvents ( ) : void {
@@ -93,13 +93,13 @@ module Netcode {
93
93
94
94
// Object open/close
95
95
on ( "objSetOpen" , ( msg : any ) => {
96
- const obj = findObjectByPID ( msg . pid ) ;
97
- console . assert ( obj !== null , "objSetOpen: No such object" ) ;
96
+ const obj = findObjectByUID ( msg . uid ) ;
97
+ console . assert ( obj !== null , "net. objSetOpen: No such object" ) ;
98
98
setObjectOpen ( obj , msg . open , false , false ) ;
99
99
} ) ;
100
100
101
101
Events . on ( "objSetOpen" , ( msg : any ) => {
102
- send ( "objSetOpen" , { pid : msg . obj . pid , open : msg . open } ) ;
102
+ send ( "objSetOpen" , { uid : msg . obj . uid , open : msg . open } ) ;
103
103
} ) ;
104
104
}
105
105
@@ -155,6 +155,10 @@ module Netcode {
155
155
156
156
send ( "changeElevation" , { elevation : currentElevation , position : player . position , orientation : player . orientation } ) ;
157
157
} ) ;
158
+
159
+ Events . on ( "objMove" , ( e : any ) => {
160
+ send ( "objMove" , { uid : e . obj . uid , position : e . position } ) ;
161
+ } ) ;
158
162
}
159
163
160
164
export function join ( ) : void {
@@ -174,6 +178,17 @@ module Netcode {
174
178
gMap . objects [ currentElevation ] . push ( netPlayer ) ;
175
179
}
176
180
} ) ;
181
+
182
+ on ( "objMove" , ( e : any ) => {
183
+ const obj = findObjectByUID ( e . uid ) ;
184
+ console . assert ( obj !== null , "net.objMove: No such object" ) ;
185
+
186
+ console . log ( "Move: uid %o, obj %o, pos %o" , e . uid , obj , e . position ) ;
187
+
188
+ // Doesn't matter if we signal events or not, we're on the guest -- we won't be sending them (for now).
189
+ // If this changes, we shouldn't signal events here.
190
+ obj . move ( e . position ) ;
191
+ } ) ;
177
192
}
178
193
179
194
export function changeMap ( ) : void {
0 commit comments