Merge pull request #83 from thecodingmachine/cleanup_rename_frame
Cleanup: renaming "frame" to "character"
This commit is contained in:
commit
c59d693f6e
@ -250,7 +250,7 @@ export class IoSocketController {
|
|||||||
socket.roomId = message.roomId;
|
socket.roomId = message.roomId;
|
||||||
socket.userId = message.userId;
|
socket.userId = message.userId;
|
||||||
socket.name = message.name;
|
socket.name = message.name;
|
||||||
socket.frame = message.frame;
|
socket.character = message.character;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshUserPosition() {
|
refreshUserPosition() {
|
||||||
|
@ -7,6 +7,6 @@ export interface ExSocketInterface extends Socket {
|
|||||||
webRtcRoomId: string;
|
webRtcRoomId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
name: string;
|
name: string;
|
||||||
frame: string;
|
character: string;
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
|
|||||||
roomId: socket.roomId,
|
roomId: socket.roomId,
|
||||||
position: socket.position,
|
position: socket.position,
|
||||||
name: socket.name,
|
name: socket.name,
|
||||||
frame: socket.frame,
|
character: socket.character,
|
||||||
};
|
};
|
||||||
let dataArray = <any>[];
|
let dataArray = <any>[];
|
||||||
if (mapPositionUserByRoom.get(data.roomId)) {
|
if (mapPositionUserByRoom.get(data.roomId)) {
|
||||||
@ -47,4 +47,4 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
RefreshUserPositionFunction
|
RefreshUserPositionFunction
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ export class Message {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
frame: string;
|
character: string;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any) {
|
||||||
if (!data.userId || !data.roomId) {
|
if (!data.userId || !data.roomId) {
|
||||||
@ -11,7 +11,7 @@ export class Message {
|
|||||||
this.userId = data.userId;
|
this.userId = data.userId;
|
||||||
this.roomId = data.roomId;
|
this.roomId = data.roomId;
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
this.frame = data.frame;
|
this.character = data.character;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
@ -19,7 +19,7 @@ export class Message {
|
|||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
frame: this.frame
|
character: this.character
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,18 @@ import {Message} from "../src/Model/Websocket/Message";
|
|||||||
|
|
||||||
describe("Message Model", () => {
|
describe("Message Model", () => {
|
||||||
it("should find userId and roomId", () => {
|
it("should find userId and roomId", () => {
|
||||||
let message = {userId: "test1", roomId: "test2", name: "foo", frame: "user"};
|
let message = {userId: "test1", roomId: "test2", name: "foo", character: "user"};
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
expect(messageObject.userId).toBe("test1");
|
expect(messageObject.userId).toBe("test1");
|
||||||
expect(messageObject.roomId).toBe("test2");
|
expect(messageObject.roomId).toBe("test2");
|
||||||
expect(messageObject.name).toBe("foo");
|
expect(messageObject.name).toBe("foo");
|
||||||
expect(messageObject.frame).toBe("user");
|
expect(messageObject.character).toBe("user");
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should expose a toJson method", () => {
|
it("should expose a toJson method", () => {
|
||||||
let message = {userId: "test1", roomId: "test2", name: "foo", frame: "user"};
|
let message = {userId: "test1", roomId: "test2", name: "foo", character: "user"};
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo", frame: "user"});
|
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo", character: "user"});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should find throw error when no userId", () => {
|
it("should find throw error when no userId", () => {
|
||||||
@ -37,4 +37,4 @@ describe("Message Model", () => {
|
|||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -20,13 +20,13 @@ class Message {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
frame: string;
|
character: string;
|
||||||
|
|
||||||
constructor(userId : string, roomId : string, name: string, frame: string) {
|
constructor(userId : string, roomId : string, name: string, character: string) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.frame = frame;
|
this.character = character;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
@ -34,7 +34,7 @@ class Message {
|
|||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
frame: this.frame
|
character: this.character
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,15 +73,15 @@ export interface MessageUserPositionInterface {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
frame: string;
|
character: string;
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageUserPosition extends Message implements MessageUserPositionInterface{
|
class MessageUserPosition extends Message implements MessageUserPositionInterface{
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
|
|
||||||
constructor(userId : string, roomId : string, point : Point, name: string, frame: string) {
|
constructor(userId : string, roomId : string, point : Point, name: string, character: string) {
|
||||||
super(userId, roomId, name, frame);
|
super(userId, roomId, name, character);
|
||||||
this.position = point;
|
this.position = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ class ListMessageUserPosition {
|
|||||||
userPosition.position.direction
|
userPosition.position.direction
|
||||||
),
|
),
|
||||||
userPosition.name,
|
userPosition.name,
|
||||||
userPosition.frame
|
userPosition.character
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -141,11 +141,11 @@ export interface ConnexionInterface {
|
|||||||
userId: string;
|
userId: string;
|
||||||
startedRoom: string;
|
startedRoom: string;
|
||||||
|
|
||||||
createConnexion(frameSelected: string): Promise<any>;
|
createConnexion(characterSelected: string): Promise<any>;
|
||||||
|
|
||||||
joinARoom(roomId: string, frame: string): void;
|
joinARoom(roomId: string, character: string): void;
|
||||||
|
|
||||||
sharePosition(x: number, y: number, direction: string, frame: string): void;
|
sharePosition(x: number, y: number, direction: string, character: string): void;
|
||||||
|
|
||||||
positionOfAllUser(): void;
|
positionOfAllUser(): void;
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ export class Connexion implements ConnexionInterface {
|
|||||||
this.GameManager = GameManager;
|
this.GameManager = GameManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
createConnexion(frameSelected: string): Promise<ConnexionInterface> {
|
createConnexion(characterSelected: string): Promise<ConnexionInterface> {
|
||||||
return Axios.post(`${API_URL}/login`, {email: this.email})
|
return Axios.post(`${API_URL}/login`, {email: this.email})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.token = res.data.token;
|
this.token = res.data.token;
|
||||||
@ -187,10 +187,10 @@ export class Connexion implements ConnexionInterface {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//join the room
|
//join the room
|
||||||
this.joinARoom(this.startedRoom, frameSelected);
|
this.joinARoom(this.startedRoom, characterSelected);
|
||||||
|
|
||||||
//share your first position
|
//share your first position
|
||||||
this.sharePosition(0, 0, frameSelected);
|
this.sharePosition(0, 0, characterSelected);
|
||||||
|
|
||||||
this.positionOfAllUser();
|
this.positionOfAllUser();
|
||||||
|
|
||||||
@ -210,15 +210,15 @@ export class Connexion implements ConnexionInterface {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param roomId
|
* @param roomId
|
||||||
* @param frame
|
* @param character
|
||||||
*/
|
*/
|
||||||
joinARoom(roomId: string, frame: string): void {
|
joinARoom(roomId: string, character: string): void {
|
||||||
let messageUserPosition = new MessageUserPosition(
|
let messageUserPosition = new MessageUserPosition(
|
||||||
this.userId,
|
this.userId,
|
||||||
this.startedRoom,
|
this.startedRoom,
|
||||||
new Point(0, 0),
|
new Point(0, 0),
|
||||||
this.email,
|
this.email,
|
||||||
frame
|
character
|
||||||
);
|
);
|
||||||
this.socket.emit(EventMessage.JOIN_ROOM, messageUserPosition.toString());
|
this.socket.emit(EventMessage.JOIN_ROOM, messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
@ -227,10 +227,10 @@ export class Connexion implements ConnexionInterface {
|
|||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @param frame
|
* @param character
|
||||||
* @param direction
|
* @param direction
|
||||||
*/
|
*/
|
||||||
sharePosition(x : number, y : number, frame : string, direction : string = "none") : void{
|
sharePosition(x : number, y : number, character : string, direction : string = "none") : void{
|
||||||
if(!this.socket){
|
if(!this.socket){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ export class Connexion implements ConnexionInterface {
|
|||||||
ROOM[0],
|
ROOM[0],
|
||||||
new Point(x, y, direction),
|
new Point(x, y, direction),
|
||||||
this.email,
|
this.email,
|
||||||
frame
|
character
|
||||||
);
|
);
|
||||||
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
|
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export interface HasMovedEvent {
|
|||||||
direction: string;
|
direction: string;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
frame: string;
|
character: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
@ -27,17 +27,17 @@ export class GameManager {
|
|||||||
private currentGameScene: GameScene;
|
private currentGameScene: GameScene;
|
||||||
private playerName: string;
|
private playerName: string;
|
||||||
SimplePeer : SimplePeerInterface;
|
SimplePeer : SimplePeerInterface;
|
||||||
private frameUserSelected: string;
|
private characterUserSelected: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(name: string, frameUserSelected : string) {
|
connect(name: string, characterUserSelected : string) {
|
||||||
this.playerName = name;
|
this.playerName = name;
|
||||||
this.frameUserSelected = frameUserSelected;
|
this.characterUserSelected = characterUserSelected;
|
||||||
this.ConnexionInstance = new Connexion(name, this);
|
this.ConnexionInstance = new Connexion(name, this);
|
||||||
return this.ConnexionInstance.createConnexion(frameUserSelected).then(() => {
|
return this.ConnexionInstance.createConnexion(characterUserSelected).then(() => {
|
||||||
this.SimplePeer = new SimplePeer(this.ConnexionInstance);
|
this.SimplePeer = new SimplePeer(this.ConnexionInstance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -100,12 +100,12 @@ export class GameManager {
|
|||||||
return this.playerName;
|
return this.playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFrameSelected(): string {
|
getCharacterSelected(): string {
|
||||||
return this.frameUserSelected;
|
return this.characterUserSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
pushPlayerPosition(event: HasMovedEvent) {
|
pushPlayerPosition(event: HasMovedEvent) {
|
||||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.frame, event.direction);
|
this.ConnexionInstance.sharePosition(event.x, event.y, event.character, event.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
this.startX,
|
this.startX,
|
||||||
this.startY,
|
this.startY,
|
||||||
this.GameManager.getPlayerName(),
|
this.GameManager.getPlayerName(),
|
||||||
this.GameManager.getFrameSelected()
|
this.GameManager.getCharacterSelected()
|
||||||
);
|
);
|
||||||
this.CurrentPlayer.initAnimation();
|
this.CurrentPlayer.initAnimation();
|
||||||
|
|
||||||
@ -286,16 +286,16 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
MessageUserPosition.position.x,
|
MessageUserPosition.position.x,
|
||||||
MessageUserPosition.position.y,
|
MessageUserPosition.position.y,
|
||||||
MessageUserPosition.name,
|
MessageUserPosition.name,
|
||||||
MessageUserPosition.frame
|
MessageUserPosition.character
|
||||||
);
|
);
|
||||||
player.initAnimation();
|
player.initAnimation();
|
||||||
this.MapPlayers.add(player);
|
this.MapPlayers.add(player);
|
||||||
player.updatePosition(MessageUserPosition);
|
player.updatePosition(MessageUserPosition);
|
||||||
|
|
||||||
//init colision
|
//init collision
|
||||||
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
/*this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
||||||
CurrentPlayer.say("Hello, how are you ? ");
|
CurrentPlayer.say("Hello, how are you ? ");
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
|
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
|
||||||
|
@ -83,12 +83,12 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
}
|
}
|
||||||
if (x !== 0 || y !== 0) {
|
if (x !== 0 || y !== 0) {
|
||||||
this.move(x, y);
|
this.move(x, y);
|
||||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, frame: this.PlayerTexture});
|
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, character: this.PlayerTexture});
|
||||||
} else {
|
} else {
|
||||||
if (this.previousMove !== PlayerAnimationNames.None) {
|
if (this.previousMove !== PlayerAnimationNames.None) {
|
||||||
direction = PlayerAnimationNames.None;
|
direction = PlayerAnimationNames.None;
|
||||||
this.stop();
|
this.stop();
|
||||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, frame: this.PlayerTexture});
|
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, character: this.PlayerTexture});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user