Commit 02574a7e authored by chechunchi's avatar chechunchi

update penetrate.ts and penetrate.json

parent 6f421e01
Pipeline #19523 failed with stages
in 2 minutes and 37 seconds
......@@ -20,4 +20,18 @@
}
]
}
"33": {
"protoType": "shuffle_hand",
"fields": [
{
"fieldName": "player",
"fieldType": "uint8"
},
{
"fieldName": "hands",
"fieldType": "repeated",
"repeatedType": "uint32"
}
]
}
}
......@@ -13,7 +13,8 @@ const ReadFieldHandlerMap: Map<string, readFieldHandler> = new Map([
["CardLocation", (reader) => reader.readCardLocation()],
]);
const MsgConstructorMap: Map<string, Constructor> = new Map([
["move", ygopro.StocGameMessage.MsgMove],
["move", ygopro.StocGameMessage.MsgMove as Constructor],
["shuffle_hand", ygopro.StocGameMessage.MsgShuffleHand],
]);
export interface penetrateType {
......@@ -21,6 +22,7 @@ export interface penetrateType {
fields: {
fieldName: string;
fieldType: string;
repeatedType?: string;
}[];
}
......@@ -46,6 +48,22 @@ class PenetrateManager {
return undefined;
}
private readRepeatedField(reader: BufferReader, repeatedType: string): any {
const handler = this.readFieldHandlerMap.get(repeatedType);
if (handler) {
const count = reader.readUint8();
let repeated = [];
for (let i = 0; i < count; i++) {
repeated.push(handler(reader));
}
return repeated;
}
return undefined;
}
private constructMsg(protoType: string, object: any): any {
const constructor = this.msgConstructorMap.get(protoType);
......@@ -65,7 +83,10 @@ class PenetrateManager {
let object: any = {};
for (let field of fields) {
object[field.fieldName] = this.readField(reader, field.fieldType);
object[field.fieldName] =
field.fieldType === "repeated" && field.repeatedType
? this.readRepeatedField(reader, field.repeatedType)
: this.readField(reader, field.fieldType);
}
gameMsg[protoType] = this.constructMsg(protoType, object);
......
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