Commit 30d1301e authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/hint' into 'main'

Feat/hint

See merge request mycard/Neos!30
parents 1b9b2fca e08981e6
neos-protobuf @ b1387888
Subproject commit 2006e72d50bfb10cf78573eb6327a3e8ded39133 Subproject commit b1387888e6e895e186f5dde1ff986f11305a3b84
...@@ -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, 3, 4]]; #one_of_decls: number[][] = [[1, 2, 3, 4, 5]];
constructor( constructor(
data?: data?:
| any[] | any[]
...@@ -3110,24 +3110,35 @@ export namespace ygopro { ...@@ -3110,24 +3110,35 @@ export namespace ygopro {
draw?: never; draw?: never;
new_turn?: never; new_turn?: never;
new_phase?: never; new_phase?: never;
hint?: never;
} }
| { | {
start?: never; start?: never;
draw?: StocGameMessage.MsgDraw; draw?: StocGameMessage.MsgDraw;
new_turn?: never; new_turn?: never;
new_phase?: never; new_phase?: never;
hint?: never;
} }
| { | {
start?: never; start?: never;
draw?: never; draw?: never;
new_turn?: StocGameMessage.MsgNewTurn; new_turn?: StocGameMessage.MsgNewTurn;
new_phase?: never; new_phase?: never;
hint?: never;
} }
| { | {
start?: never; start?: never;
draw?: never; draw?: never;
new_turn?: never; new_turn?: never;
new_phase?: StocGameMessage.MsgNewPhase; new_phase?: StocGameMessage.MsgNewPhase;
hint?: never;
}
| {
start?: never;
draw?: never;
new_turn?: never;
new_phase?: never;
hint?: StocGameMessage.MsgHint;
} }
)) ))
) { ) {
...@@ -3153,6 +3164,9 @@ export namespace ygopro { ...@@ -3153,6 +3164,9 @@ export namespace ygopro {
if ("new_phase" in data && data.new_phase != undefined) { if ("new_phase" in data && data.new_phase != undefined) {
this.new_phase = data.new_phase; this.new_phase = data.new_phase;
} }
if ("hint" in data && data.hint != undefined) {
this.hint = data.hint;
}
} }
} }
get start() { get start() {
...@@ -3207,17 +3221,37 @@ export namespace ygopro { ...@@ -3207,17 +3221,37 @@ export namespace ygopro {
get has_new_phase() { get has_new_phase() {
return pb_1.Message.getField(this, 4) != null; return pb_1.Message.getField(this, 4) != null;
} }
get hint() {
return pb_1.Message.getWrapperField(
this,
StocGameMessage.MsgHint,
5
) as StocGameMessage.MsgHint;
}
set hint(value: StocGameMessage.MsgHint) {
pb_1.Message.setOneofWrapperField(this, 5, this.#one_of_decls[0], value);
}
get has_hint() {
return pb_1.Message.getField(this, 5) != null;
}
get gameMsg() { get gameMsg() {
const cases: { const cases: {
[index: number]: "none" | "start" | "draw" | "new_turn" | "new_phase"; [index: number]:
| "none"
| "start"
| "draw"
| "new_turn"
| "new_phase"
| "hint";
} = { } = {
0: "none", 0: "none",
1: "start", 1: "start",
2: "draw", 2: "draw",
3: "new_turn", 3: "new_turn",
4: "new_phase", 4: "new_phase",
5: "hint",
}; };
return cases[pb_1.Message.computeOneofCase(this, [1, 2, 3, 4])]; return cases[pb_1.Message.computeOneofCase(this, [1, 2, 3, 4, 5])];
} }
static fromObject(data: { static fromObject(data: {
start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>; start?: ReturnType<typeof StocGameMessage.MsgStart.prototype.toObject>;
...@@ -3228,6 +3262,7 @@ export namespace ygopro { ...@@ -3228,6 +3262,7 @@ export namespace ygopro {
new_phase?: ReturnType< new_phase?: ReturnType<
typeof StocGameMessage.MsgNewPhase.prototype.toObject typeof StocGameMessage.MsgNewPhase.prototype.toObject
>; >;
hint?: ReturnType<typeof StocGameMessage.MsgHint.prototype.toObject>;
}): StocGameMessage { }): StocGameMessage {
const message = new StocGameMessage({}); const message = new StocGameMessage({});
if (data.start != null) { if (data.start != null) {
...@@ -3244,6 +3279,9 @@ export namespace ygopro { ...@@ -3244,6 +3279,9 @@ export namespace ygopro {
data.new_phase data.new_phase
); );
} }
if (data.hint != null) {
message.hint = StocGameMessage.MsgHint.fromObject(data.hint);
}
return message; return message;
} }
toObject() { toObject() {
...@@ -3256,6 +3294,7 @@ export namespace ygopro { ...@@ -3256,6 +3294,7 @@ export namespace ygopro {
new_phase?: ReturnType< new_phase?: ReturnType<
typeof StocGameMessage.MsgNewPhase.prototype.toObject typeof StocGameMessage.MsgNewPhase.prototype.toObject
>; >;
hint?: ReturnType<typeof StocGameMessage.MsgHint.prototype.toObject>;
} = {}; } = {};
if (this.start != null) { if (this.start != null) {
data.start = this.start.toObject(); data.start = this.start.toObject();
...@@ -3269,6 +3308,9 @@ export namespace ygopro { ...@@ -3269,6 +3308,9 @@ export namespace ygopro {
if (this.new_phase != null) { if (this.new_phase != null) {
data.new_phase = this.new_phase.toObject(); data.new_phase = this.new_phase.toObject();
} }
if (this.hint != null) {
data.hint = this.hint.toObject();
}
return data; return data;
} }
serialize(): Uint8Array; serialize(): Uint8Array;
...@@ -3287,6 +3329,8 @@ export namespace ygopro { ...@@ -3287,6 +3329,8 @@ export namespace ygopro {
writer.writeMessage(4, this.new_phase, () => writer.writeMessage(4, this.new_phase, () =>
this.new_phase.serialize(writer) this.new_phase.serialize(writer)
); );
if (this.has_hint)
writer.writeMessage(5, this.hint, () => this.hint.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 {
...@@ -3327,6 +3371,12 @@ export namespace ygopro { ...@@ -3327,6 +3371,12 @@ export namespace ygopro {
StocGameMessage.MsgNewPhase.deserialize(reader)) StocGameMessage.MsgNewPhase.deserialize(reader))
); );
break; break;
case 5:
reader.readMessage(
message.hint,
() => (message.hint = StocGameMessage.MsgHint.deserialize(reader))
);
break;
default: default:
reader.skipField(); reader.skipField();
} }
...@@ -3868,5 +3918,145 @@ export namespace ygopro { ...@@ -3868,5 +3918,145 @@ export namespace ygopro {
END = 10, END = 10,
} }
} }
export class MsgHint extends pb_1.Message {
#one_of_decls: number[][] = [];
constructor(
data?:
| any[]
| {
hint_type?: StocGameMessage.MsgHint.HintType;
player?: number;
hint_data?: 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 ("hint_type" in data && data.hint_type != undefined) {
this.hint_type = data.hint_type;
}
if ("player" in data && data.player != undefined) {
this.player = data.player;
}
if ("hint_data" in data && data.hint_data != undefined) {
this.hint_data = data.hint_data;
}
}
}
get hint_type() {
return pb_1.Message.getFieldWithDefault(
this,
1,
StocGameMessage.MsgHint.HintType.UNKNOWN
) as StocGameMessage.MsgHint.HintType;
}
set hint_type(value: StocGameMessage.MsgHint.HintType) {
pb_1.Message.setField(this, 1, value);
}
get player() {
return pb_1.Message.getFieldWithDefault(this, 2, 0) as number;
}
set player(value: number) {
pb_1.Message.setField(this, 2, value);
}
get hint_data() {
return pb_1.Message.getFieldWithDefault(this, 3, 0) as number;
}
set hint_data(value: number) {
pb_1.Message.setField(this, 3, value);
}
static fromObject(data: {
hint_type?: StocGameMessage.MsgHint.HintType;
player?: number;
hint_data?: number;
}): MsgHint {
const message = new MsgHint({});
if (data.hint_type != null) {
message.hint_type = data.hint_type;
}
if (data.player != null) {
message.player = data.player;
}
if (data.hint_data != null) {
message.hint_data = data.hint_data;
}
return message;
}
toObject() {
const data: {
hint_type?: StocGameMessage.MsgHint.HintType;
player?: number;
hint_data?: number;
} = {};
if (this.hint_type != null) {
data.hint_type = this.hint_type;
}
if (this.player != null) {
data.player = this.player;
}
if (this.hint_data != null) {
data.hint_data = this.hint_data;
}
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.hint_type != StocGameMessage.MsgHint.HintType.UNKNOWN)
writer.writeEnum(1, this.hint_type);
if (this.player != 0) writer.writeInt32(2, this.player);
if (this.hint_data != 0) writer.writeInt32(3, this.hint_data);
if (!w) return writer.getResultBuffer();
}
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): MsgHint {
const reader =
bytes instanceof pb_1.BinaryReader
? bytes
: new pb_1.BinaryReader(bytes),
message = new MsgHint();
while (reader.nextField()) {
if (reader.isEndGroup()) break;
switch (reader.getFieldNumber()) {
case 1:
message.hint_type = reader.readEnum();
break;
case 2:
message.player = reader.readInt32();
break;
case 3:
message.hint_data = reader.readInt32();
break;
default:
reader.skipField();
}
}
return message;
}
serializeBinary(): Uint8Array {
return this.serialize();
}
static deserializeBinary(bytes: Uint8Array): MsgHint {
return MsgHint.deserialize(bytes);
}
}
export namespace MsgHint {
export enum HintType {
UNKNOWN = 0,
SELECT_LOCATION = 1,
SELECT_EFFECT = 2,
SELECT_RACE = 3,
SELECT_ATTRIBUTE = 4,
SELECT_NUMBER = 5,
SELECT_REGION = 6,
}
}
} }
} }
...@@ -2,6 +2,7 @@ const OFFSET_UINT8 = 1; ...@@ -2,6 +2,7 @@ const OFFSET_UINT8 = 1;
const OFFSET_INT8 = 1; const OFFSET_INT8 = 1;
const OFFSET_UINT16 = 2; const OFFSET_UINT16 = 2;
const OFFSET_UINT32 = 4; const OFFSET_UINT32 = 4;
const OFFSET_INT32 = 4;
export class BufferReader { export class BufferReader {
dataView: DataView; dataView: DataView;
...@@ -41,4 +42,11 @@ export class BufferReader { ...@@ -41,4 +42,11 @@ export class BufferReader {
return ret; return ret;
} }
readInt32(): number {
const ret = this.dataView.getInt32(this.offset, this.littleEndian);
this.offset += OFFSET_INT32;
return ret;
}
} }
...@@ -27,3 +27,4 @@ export const MSG_START = 4; ...@@ -27,3 +27,4 @@ export const MSG_START = 4;
export const MSG_DRAW = 90; export const MSG_DRAW = 90;
export const MSG_NEW_TURN = 40; export const MSG_NEW_TURN = 40;
export const MSG_NEW_PHASE = 41; export const MSG_NEW_PHASE = 41;
export const MSG_HINT = 2;
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
const LITTLE_ENDIAN = true;
/*
* Msg Hint
*
* @param hintType: char - 提示的类型
* @param hintPlayer: char - 提示的玩家
* @param hintData: int32 - 提示的数据
*
* @usage - 显示提示信息
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, LITTLE_ENDIAN);
const hintCommand = reader.readUint8();
const hintPlayer = reader.readUint8();
const hintData = reader.readInt32();
let hintType = ygopro.StocGameMessage.MsgHint.HintType.UNKNOWN;
switch (hintCommand) {
case 0x01: {
// TODO
break;
}
case 0x02: {
// TODO
break;
}
case 0x03: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_LOCATION;
break;
}
case 0x04: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_EFFECT;
break;
}
case 0x05: {
// TODO
break;
}
case 0x06: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_RACE;
break;
}
case 0x07: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_ATTRIBUTE;
break;
}
case 0x08: {
// TODO
break;
}
case 0x09: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_NUMBER;
break;
}
case 0x0a: {
// TODO
break;
}
case 0x0b: {
hintType = ygopro.StocGameMessage.MsgHint.HintType.SELECT_REGION;
break;
}
default: {
break;
}
}
return new ygopro.StocGameMessage.MsgHint({
hint_type: hintType,
player: hintPlayer,
hint_data: hintData,
});
};
...@@ -10,6 +10,7 @@ import MsgStartAdapter from "./start"; ...@@ -10,6 +10,7 @@ import MsgStartAdapter from "./start";
import MsgDrawAdapter from "./draw"; import MsgDrawAdapter from "./draw";
import MsgNewTurnAdapter from "./newTurn"; import MsgNewTurnAdapter from "./newTurn";
import MsgNewPhaseAdapter from "./newPhase"; import MsgNewPhaseAdapter from "./newPhase";
import MsgHintAdapter from "./hint";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -55,6 +56,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -55,6 +56,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_HINT: {
gameMsg.hint = MsgHintAdapter(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
...@@ -4,6 +4,7 @@ import onMsgStart from "./start"; ...@@ -4,6 +4,7 @@ import onMsgStart from "./start";
import onMsgDraw from "./draw"; import onMsgDraw from "./draw";
import onMsgNewTurn from "./newTurn"; import onMsgNewTurn from "./newTurn";
import onMsgNewPhase from "./newPhase"; import onMsgNewPhase from "./newPhase";
import onMsgHint from "./hint";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -38,6 +39,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -38,6 +39,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "hint": {
const hint = msg.hint;
onMsgHint(hint, 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 (
hint: ygopro.StocGameMessage.MsgHint,
dispatch: AppDispatch
) => {
// TODO
console.log(hint);
};
#!/bin/bash
# 更新PB代码
protoc -I=./neos-protobuf --ts_out=./src/api/ocgcore ./neos-protobuf/idl/ocgcore.proto
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