Commit c5d4e353 authored by Chunchi Che's avatar Chunchi Che

add MsgNewTurn

parent f334f373
Pipeline #18296 passed with stages
in 2 minutes and 15 seconds
Subproject commit cdceb9956b250e56cc59c18936872cdda3f3fb2c Subproject commit f4278cdb78436dd2fd2a521f825c7498eef7b65d
...@@ -3100,7 +3100,7 @@ export namespace ygopro { ...@@ -3100,7 +3100,7 @@ export namespace ygopro {
} }
} }
export class StocGameMessage extends pb_1.Message { export class StocGameMessage extends pb_1.Message {
#one_of_decls: number[][] = [[1, 2]]; #one_of_decls: number[][] = [[1, 2, 3]];
constructor( constructor(
data?: data?:
| any[] | any[]
...@@ -3108,10 +3108,17 @@ export namespace ygopro { ...@@ -3108,10 +3108,17 @@ export namespace ygopro {
| { | {
start?: StocGameMessage.MsgStart; start?: StocGameMessage.MsgStart;
draw?: never; draw?: never;
new_turn?: never;
} }
| { | {
start?: never; start?: never;
draw?: StocGameMessage.MsgDraw; draw?: StocGameMessage.MsgDraw;
new_turn?: never;
}
| {
start?: never;
draw?: never;
new_turn?: StocGameMessage.MsgNewTurn;
} }
)) ))
) { ) {
...@@ -3131,6 +3138,9 @@ export namespace ygopro { ...@@ -3131,6 +3138,9 @@ export namespace ygopro {
if ("draw" in data && data.draw != undefined) { if ("draw" in data && data.draw != undefined) {
this.draw = data.draw; this.draw = data.draw;
} }
if ("new_turn" in data && data.new_turn != undefined) {
this.new_turn = data.new_turn;
}
} }
} }
get start() { get start() {
...@@ -3159,19 +3169,36 @@ export namespace ygopro { ...@@ -3159,19 +3169,36 @@ export namespace ygopro {
get has_draw() { get has_draw() {
return pb_1.Message.getField(this, 2) != null; return pb_1.Message.getField(this, 2) != null;
} }
get new_turn() {
return pb_1.Message.getWrapperField(
this,
StocGameMessage.MsgNewTurn,
3
) as StocGameMessage.MsgNewTurn;
}
set new_turn(value: StocGameMessage.MsgNewTurn) {
pb_1.Message.setOneofWrapperField(this, 3, this.#one_of_decls[0], value);
}
get has_new_turn() {
return pb_1.Message.getField(this, 3) != null;
}
get gameMsg() { get gameMsg() {
const cases: { const cases: {
[index: number]: "none" | "start" | "draw"; [index: number]: "none" | "start" | "draw" | "new_turn";
} = { } = {
0: "none", 0: "none",
1: "start", 1: "start",
2: "draw", 2: "draw",
3: "new_turn",
}; };
return cases[pb_1.Message.computeOneofCase(this, [1, 2])]; return cases[pb_1.Message.computeOneofCase(this, [1, 2, 3])];
} }
static fromObject(data: { static fromObject(data: {
start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>; start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>;
draw?: ReturnType<typeof StocGameMessage.MsgDraw.prototype.toObject>; draw?: ReturnType<typeof StocGameMessage.MsgDraw.prototype.toObject>;
new_turn?: ReturnType<
typeof StocGameMessage.MsgNewTurn.prototype.toObject
>;
}): StocGameMessage { }): StocGameMessage {
const message = new StocGameMessage({}); const message = new StocGameMessage({});
if (data.start != null) { if (data.start != null) {
...@@ -3180,12 +3207,18 @@ export namespace ygopro { ...@@ -3180,12 +3207,18 @@ export namespace ygopro {
if (data.draw != null) { if (data.draw != null) {
message.draw = StocGameMessage.MsgDraw.fromObject(data.draw); message.draw = StocGameMessage.MsgDraw.fromObject(data.draw);
} }
if (data.new_turn != null) {
message.new_turn = StocGameMessage.MsgNewTurn.fromObject(data.new_turn);
}
return message; return message;
} }
toObject() { toObject() {
const data: { const data: {
start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>; start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>;
draw?: ReturnType<typeof StocGameMessage.MsgDraw.prototype.toObject>; draw?: ReturnType<typeof StocGameMessage.MsgDraw.prototype.toObject>;
new_turn?: ReturnType<
typeof StocGameMessage.MsgNewTurn.prototype.toObject
>;
} = {}; } = {};
if (this.start != null) { if (this.start != null) {
data.start = this.start.toObject(); data.start = this.start.toObject();
...@@ -3193,6 +3226,9 @@ export namespace ygopro { ...@@ -3193,6 +3226,9 @@ export namespace ygopro {
if (this.draw != null) { if (this.draw != null) {
data.draw = this.draw.toObject(); data.draw = this.draw.toObject();
} }
if (this.new_turn != null) {
data.new_turn = this.new_turn.toObject();
}
return data; return data;
} }
serialize(): Uint8Array; serialize(): Uint8Array;
...@@ -3203,6 +3239,10 @@ export namespace ygopro { ...@@ -3203,6 +3239,10 @@ export namespace ygopro {
writer.writeMessage(1, this.start, () => this.start.serialize(writer)); writer.writeMessage(1, this.start, () => this.start.serialize(writer));
if (this.has_draw) if (this.has_draw)
writer.writeMessage(2, this.draw, () => this.draw.serialize(writer)); writer.writeMessage(2, this.draw, () => this.draw.serialize(writer));
if (this.has_new_turn)
writer.writeMessage(3, this.new_turn, () =>
this.new_turn.serialize(writer)
);
if (!w) return writer.getResultBuffer(); if (!w) return writer.getResultBuffer();
} }
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): StocGameMessage { static deserialize(bytes: Uint8Array | pb_1.BinaryReader): StocGameMessage {
...@@ -3227,6 +3267,14 @@ export namespace ygopro { ...@@ -3227,6 +3267,14 @@ export namespace ygopro {
() => (message.draw = StocGameMessage.MsgDraw.deserialize(reader)) () => (message.draw = StocGameMessage.MsgDraw.deserialize(reader))
); );
break; break;
case 3:
reader.readMessage(
message.new_turn,
() =>
(message.new_turn =
StocGameMessage.MsgNewTurn.deserialize(reader))
);
break;
default: default:
reader.skipField(); reader.skipField();
} }
...@@ -3590,5 +3638,83 @@ export namespace ygopro { ...@@ -3590,5 +3638,83 @@ export namespace ygopro {
return MsgDraw.deserialize(bytes); return MsgDraw.deserialize(bytes);
} }
} }
export class MsgNewTurn extends pb_1.Message {
#one_of_decls: number[][] = [];
constructor(
data?:
| any[]
| {
player?: number;
}
) {
super();
pb_1.Message.initialize(
this,
Array.isArray(data) ? data : [],
0,
-1,
[],
this.#one_of_decls
);
if (!Array.isArray(data) && typeof data == "object") {
if ("player" in data && data.player != undefined) {
this.player = data.player;
}
}
}
get player() {
return pb_1.Message.getFieldWithDefault(this, 1, 0) as number;
}
set player(value: number) {
pb_1.Message.setField(this, 1, value);
}
static fromObject(data: { player?: number }): MsgNewTurn {
const message = new MsgNewTurn({});
if (data.player != null) {
message.player = data.player;
}
return message;
}
toObject() {
const data: {
player?: number;
} = {};
if (this.player != null) {
data.player = this.player;
}
return data;
}
serialize(): Uint8Array;
serialize(w: pb_1.BinaryWriter): void;
serialize(w?: pb_1.BinaryWriter): Uint8Array | void {
const writer = w || new pb_1.BinaryWriter();
if (this.player != 0) writer.writeInt32(1, this.player);
if (!w) return writer.getResultBuffer();
}
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): MsgNewTurn {
const reader =
bytes instanceof pb_1.BinaryReader
? bytes
: new pb_1.BinaryReader(bytes),
message = new MsgNewTurn();
while (reader.nextField()) {
if (reader.isEndGroup()) break;
switch (reader.getFieldNumber()) {
case 1:
message.player = reader.readInt32();
break;
default:
reader.skipField();
}
}
return message;
}
serializeBinary(): Uint8Array {
return this.serialize();
}
static deserializeBinary(bytes: Uint8Array): MsgNewTurn {
return MsgNewTurn.deserialize(bytes);
}
}
} }
} }
...@@ -25,3 +25,4 @@ export const STOC_GAME_MSG = 1; ...@@ -25,3 +25,4 @@ export const STOC_GAME_MSG = 1;
export const MSG_START = 4; export const MSG_START = 4;
export const MSG_DRAW = 90; export const MSG_DRAW = 90;
export const MSG_NEW_TURN = 40;
...@@ -8,6 +8,7 @@ import { YgoProPacket, StocAdapter } from "../../packet"; ...@@ -8,6 +8,7 @@ import { YgoProPacket, StocAdapter } from "../../packet";
import * as GAME_MSG from "../../protoDecl"; import * as GAME_MSG from "../../protoDecl";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
import MsgDrawAdapter from "./draw"; import MsgDrawAdapter from "./draw";
import MsgNewTurnAdapter from "./newTurn";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -43,6 +44,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -43,6 +44,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_NEW_TURN: {
gameMsg.new_turn = MsgNewTurnAdapter(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
const LITTLE_ENDIAN = true;
/*
* MSG New Turn
*
* @param player: char - 下一个操作的玩家编号
*
* @usage - 服务端告诉前端下一个操作的玩家
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, LITTLE_ENDIAN);
const player = reader.readUint8();
return new ygopro.StocGameMessage.MsgNewTurn({
player,
});
};
...@@ -2,6 +2,7 @@ import { ygopro } from "../../api/ocgcore/idl/ocgcore"; ...@@ -2,6 +2,7 @@ import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store"; import { store } from "../../store";
import onMsgStart from "./start"; import onMsgStart from "./start";
import onMsgDraw from "./draw"; import onMsgDraw from "./draw";
import onMsgNewTurn from "./newTurn";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -22,6 +23,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -22,6 +23,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "new_turn": {
const newTurn = msg.new_turn;
onMsgNewTurn(newTurn, dispatch);
break;
}
default: { default: {
console.log("Unhandled GameMsg=" + msg.gameMsg); console.log("Unhandled GameMsg=" + msg.gameMsg);
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
export default (
newTurn: ygopro.StocGameMessage.MsgNewTurn,
dispatch: AppDispatch
) => {
// TODO
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment