Last active
October 5, 2020 00:07
-
-
Save doorbash/613022459271d768f366e8ff9e619e45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.colyseus.example.java; | |
import io.colyseus.Client; | |
import io.colyseus.Room; | |
import kotlin.Unit; | |
import kotlin.coroutines.Continuation; | |
import kotlin.coroutines.CoroutineContext; | |
import org.jetbrains.annotations.NotNull; | |
public class Main { | |
public static void main(String... args) { | |
Client client = new Client("ws://localhost:2567"); | |
client.joinOrCreate(MyState.class, | |
"game", | |
null, | |
null, | |
null, | |
new Continuation<Room<MyState>>() { | |
@NotNull | |
@Override | |
public CoroutineContext getContext() { | |
return null; | |
} | |
@Override | |
public void resumeWith(@NotNull Object o) { | |
Room<MyState> room = (Room<MyState>) o; | |
System.out.println("connected to " + room.getName()); | |
room.getState().players.setOnAdd((player, integer) -> { | |
System.out.println("added player with x = " + player.x + " to index = " + integer); | |
room.send("fire", "in the hole!"); | |
return Unit.INSTANCE; | |
}); | |
room.getOnMessageHandlers().put("hello", new Room.MessageHandler<>(Object.class, s -> { | |
System.out.println(s); | |
return Unit.INSTANCE; | |
})); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.colyseus.example.java; | |
import io.colyseus.annotations.SchemaField; | |
import io.colyseus.serializer.schema.Schema; | |
import io.colyseus.serializer.schema.types.ArraySchema; | |
import io.colyseus.serializer.schema.types.MapSchema; | |
public class MyState extends Schema { | |
@SchemaField(v1 = "0/ref", v2 = PrimitivesTest.class) | |
public PrimitivesTest primitives = new PrimitivesTest(); | |
@SchemaField(v1 = "1/array/ref", v2 = Player.class) | |
public ArraySchema<Player> players = new ArraySchema<>(Player.class); | |
@SchemaField(v1 = "2/map/ref", v2 = Cell.class) | |
public MapSchema<Cell> cells = new MapSchema<>(Cell.class); | |
} | |
class Cell extends Schema { | |
@SchemaField(v1 = "0/float32") | |
public float x; | |
@SchemaField(v1 = "1/float32") | |
public float y; | |
} | |
class PrimitivesTest extends Schema { | |
@SchemaField(v1 = "0/uint8") | |
public short _uint8; | |
@SchemaField(v1 = "1/uint16") | |
public int _uint16; | |
@SchemaField(v1 = "2/uint32") | |
public long _uint32; | |
@SchemaField(v1 = "3/uint64") | |
public long _uint64; | |
@SchemaField(v1 = "4/int8") | |
public byte _int8; | |
@SchemaField(v1 = "5/int16") | |
public short _int16; | |
@SchemaField(v1 = "6/int32") | |
public int _int32; | |
@SchemaField(v1 = "7/int64") | |
public long _int64; | |
@SchemaField(v1 = "8/float32") | |
public float _float32_n; | |
@SchemaField(v1 = "9/float32") | |
public float _float32_p; | |
@SchemaField(v1 = "10/float64") | |
public double _float64_n; | |
@SchemaField(v1 = "11/float64") | |
public double _float64_p; | |
@SchemaField(v1 = "12/boolean") | |
public boolean _boolean; | |
@SchemaField(v1 = "13/string") | |
public String _string; | |
} | |
class Player extends Schema { | |
@SchemaField(v1 = "0/int32") | |
public int x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment