File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed
Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { NetplayInput } from "./netcode/types";
22import * as utils from "./utils" ;
33import { TouchControl } from "./touchcontrols" ;
44import { Vec2 } from "./vec2" ;
5+ import { JsonObject , JsonValue } from "type-fest" ;
6+ import * as autoserialize from "./serialization/autoserialize" ;
57
68export class DefaultInput extends NetplayInput {
79 keysPressed : { [ key : string ] : boolean } = { } ;
@@ -29,6 +31,20 @@ export class DefaultInput extends NetplayInput {
2931 ( this . keysHeld . s ? - 1 : 0 ) + ( this . keysHeld . w ? 1 : 0 )
3032 ) ;
3133 }
34+
35+ /**
36+ * By default, use the auto serializer.
37+ */
38+ serialize ( ) : JsonValue {
39+ return autoserialize . serialize ( this ) ;
40+ }
41+
42+ /**
43+ * By default, use the auto deserializer.
44+ */
45+ deserialize ( value : JsonValue ) : void {
46+ autoserialize . deserialize ( value as JsonObject , this ) ;
47+ }
3248}
3349
3450export class DefaultInputReader {
Original file line number Diff line number Diff line change @@ -49,18 +49,11 @@ export abstract class NetplayInput {
4949 }
5050
5151 /**
52- * By default, use the auto serializer.
53- */
54- serialize ( ) : JsonValue {
55- return autoserialize . serialize ( this ) ;
56- }
57-
58- /**
59- * By default, use the auto deserializer.
52+ * We need to be able to serialize and deserialize the input
53+ * so we can send it across the network.
6054 */
61- deserialize ( value : JsonValue ) : void {
62- autoserialize . deserialize ( value as JsonObject , this ) ;
63- }
55+ abstract serialize ( ) : JsonValue ;
56+ abstract deserialize ( value : JsonValue ) ;
6457}
6558
6659/**
@@ -91,4 +84,4 @@ export class NetplayPlayer {
9184 getID ( ) : number {
9285 return this . id ;
9386 }
94- }
87+ }
You can’t perform that action at this time.
0 commit comments