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

optimize

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