Commit 37abfc37 authored by Chunchi Che's avatar Chunchi Che

optimize

parent 41d4757f
/* eslint valtio/avoid-this-in-proxy: 0 */
import { Omit } from "@react-spring/web";
import _ from "lodash";
import { proxy } from "valtio";
import { ygopro } from "@/api";
......@@ -41,19 +39,17 @@ const defaultInitInfo = {
extraSize: 0,
};
const initInfo: MatState["initInfo"] = (() => {
return proxy({
me: { ...defaultInitInfo },
op: { ...defaultInitInfo },
of: (controller: number) => initInfo[getWhom(controller)],
set: (controller: number, obj: Partial<InitInfo>) => {
initInfo[getWhom(controller)] = {
...initInfo[getWhom(controller)],
...obj,
};
},
});
})();
const initInfo: MatState["initInfo"] = proxy({
me: { ...defaultInitInfo },
op: { ...defaultInitInfo },
of: (controller: number) => initInfo[getWhom(controller)],
set: (controller: number, obj: Partial<InitInfo>) => {
initInfo[getWhom(controller)] = {
...initInfo[getWhom(controller)],
...obj,
};
},
});
const initialState: Omit<MatState, "reset"> = {
chains: [],
......
import { cloneDeep } from "lodash-es";
import { proxy } from "valtio";
import { ygopro } from "@/api";
......@@ -68,17 +69,11 @@ class PlaceStore implements NeosStore {
});
}
reset(): void {
// this.inner = initialState;
this.inner = {
[MZONE]: {
me: genPLaces(7),
op: genPLaces(7),
},
[SZONE]: {
me: genPLaces(6),
op: genPLaces(6),
},
};
const resetObj = cloneDeep(initialState);
Object.keys(resetObj).forEach((key) => {
// @ts-ignore
placeStore.inner[key] = resetObj[key];
});
}
}
......
/* eslint valtio/avoid-this-in-proxy: 0 */
import _ from "lodash";
import { cloneDeep } from "lodash-es";
import { proxy } from "valtio";
import { ygopro } from "@/api";
......@@ -48,7 +48,7 @@ export const playerStore = proxy<PlayerState>({
return this.player0;
},
reset() {
const resetObj = _.cloneDeep(initialState);
const resetObj = cloneDeep(initialState);
Object.keys(resetObj).forEach((key) => {
// @ts-ignore
playerStore[key] = resetObj[key];
......
import { proxy } from "valtio";
import { proxy, ref } from "valtio";
import { YgoProPacket } from "@/api/ocgcore/ocgAdapter/packet";
......@@ -17,7 +17,7 @@ interface ReplayPacket {
// 保存对局回放数据的`Store`
class ReplayStore implements NeosStore {
inner: ReplaySpot[] = [];
inner: ReplaySpot[] = ref([]);
record(ygoPacket: YgoProPacket) {
this.inner.push({
packet: ygoPacket2replayPacket(ygoPacket),
......@@ -27,7 +27,7 @@ class ReplayStore implements NeosStore {
return this.inner.map((spot) => spot.packet).map(replayPacket2arrayBuffer);
}
reset() {
this.inner = [];
this.inner.splice(0);
}
}
......
......@@ -56,6 +56,8 @@ export const EndModal: React.FC = () => {
// download the replay file
window.URL.revokeObjectURL(url);
document.body.removeChild(anchorElement);
}
onReturn();
}}
......
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