Skip to content

Commit

Permalink
Merge branch 'feat-mvp' of github.com:Mississippi-Labs/mississippi in…
Browse files Browse the repository at this point in the history
…to feat-mvp
  • Loading branch information
LidamaoHub committed Dec 11, 2023
2 parents a8ddb1f + bcdc49d commit 130f5db
Show file tree
Hide file tree
Showing 28 changed files with 937 additions and 480 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ packages/contracts/types/*
!packages/contracts/out/User.sol/
!packages/contracts/out/Plugin.sol/
!packages/contracts/out/IWorld.sol/

packages/client/dist/*
2 changes: 2 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@latticexyz/utils": "2.0.0-next.14",
"@latticexyz/world": "2.0.0-next.14",
"@pixi/react": "^7.1.1",
"@types/node": "^18.15.11",
"@vitejs/plugin-react": "^4.1.1",
"antd": "^5.12.1",
"buffer": "^6.0.3",
"contracts": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// systemCalls: { addTask, toggleTask, deleteTask },
// } = useMUD();

// console.log("tables", tables);

// const tasks = useStore((state) => {
// const records = Object.values(state.getRecords(tables.Tasks));
Expand Down
7 changes: 0 additions & 7 deletions packages/client/src/components/Battle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default function Battle(props) {
}

const setTimer = (s) => {
console.log(s)
const seconds = Number(s)
if (seconds == 0) {
forceEndFun()
Expand Down Expand Up @@ -119,11 +118,9 @@ export default function Battle(props) {
}
}
} else if (battleState == 2) {
console.log(battleState, battle)
if (curType == 'attacker' && (battle?.attackerState == 2 || battle?.attackerState == 0)) {
if (battle?.defenderState == 2 || battle?.defenderState == 0) {
setBattleState(3)
console.log(3)
}
} else if (curType == 'defender' && (battle?.defenderState == 2 || battle?.defenderState == 0)) {
if (battle?.attackerState == 2 || battle?.attackerState == 0) {
Expand Down Expand Up @@ -185,7 +182,6 @@ export default function Battle(props) {
}

const afterAttack = (role: string) => {
console.log(role)
let attackType = battle.defenderArg.toString() == '1' ? 'sprint' : battle.defenderArg.toString() == '2' ? 'sneak' : 'magic'
let data = JSON.parse(JSON.stringify(battleData))
if (role == 'left') {
Expand Down Expand Up @@ -278,7 +274,6 @@ export default function Battle(props) {
}, [battleState])

const setTacticsStepFun = (step, action) => {
console.log(step)
if (battleState != 0) return
if (action) {
setConfirmBattleData([action])
Expand All @@ -287,7 +282,6 @@ export default function Battle(props) {
}

const setSelectTactic = (tactic: number) => {
console.log(tactic)
if (battleState != 0) return
if (tactic) {
confirmBattleFun(tactic)
Expand Down Expand Up @@ -337,7 +331,6 @@ export default function Battle(props) {
localStorage.removeItem('confirmBattleData')
return
} else {
console.log(res)
let data = res.data
if (curType == 'attacker' && data?.attackerState == 0) {
setBattleState(0)
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/DuelField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const DuelField = React.forwardRef<IDuelFieldMethod>((props: IProps, ref) => {
setLeftAction('slash');
setRightAction('blink');
setEffectPositionX(680);
console.log(leftPlayer.name, 'attack', type);
if (textureMap.current[type]) {
setAttackType(type);
}
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/Log/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useRef, useState, useEffect } from 'react';
import './styles.scss';
import eventEmitter from '../../utils/eventEmitter';

console.log('eventEmitter', eventEmitter);

const Log = () => {
const [logs, setLogs] = useState([]);
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const Map = (props: IProps) => {
const cellClassCache = useRef<ICellClassCache>({});

const onMoveTo = (coordinate) => {
console.log(players, coordinate, 'onMoveTo', curId)
const { x, y, speed } = players.find((player) => player.addr.toLocaleLowerCase() === curId.toLocaleLowerCase());
const paths = bfs(simpleMapData, { x, y }, coordinate).slice(1).slice(0, Number(speed));
onPlayerMove(paths, formatMovePath(paths));
Expand Down
45 changes: 28 additions & 17 deletions packages/client/src/components/PIXIAPP/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
updatePlayerPosition
} from '@/utils/player';


PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
const { cellSize, visualWidth, visualHeight } = MapConfig;

Expand All @@ -42,22 +43,27 @@ const PIXIAPP = () => {
const [activePlayerId, setActivePlayerId] = useState('');
const [huntingPlayerId, setHuntingActivePlayerId] = useState('');

const [renderPlayers, setRenderPlayers] = useState<IPlayer[]>([]);
// const [renderPlayers, setRenderPlayers] = useState<IPlayer[]>([]);

const renderPlayersRef = useRef<IPlayer[]>([]);
const [playerUpdateTime, setPlayerUpdateTime] = useState(0);
const renderPlayers = renderPlayersRef.current;
const curPlayer = renderPlayers.find(item => item.addr === curAddr)
const moveTasks = useRef([]);
const clickedCoordinate = useRef({ x: -1, y : -1})
const playersCache = getPlayersCache(players);
useEffect(() => {
let renderPlayersArr = [...renderPlayers];
players.filter((player) => isValidPlayer(player)).forEach((player) => {
// let renderPlayersArr = [...renderPlayers];
const validPlayer = players.filter((player) => isValidPlayer(player));
validPlayer.forEach((player) => {
const renderPlayer = renderPlayers.find((rPlayer) => rPlayer.addr === player.addr);
if (renderPlayer) {
// update
if (isSamePosition(player, renderPlayer)) {
// Maybe other fields changed
Object.assign(renderPlayer, player);
} else {
if (!renderPlayer.moving && !renderPlayer.waiting) {
if (!renderPlayer.moving && !renderPlayer.waiting && getDistance(renderPlayer, player) <= MapConfig.maxAnimateDistance) {
moveTasks.current.push({
player: renderPlayer,
target: {
Expand All @@ -69,22 +75,23 @@ const PIXIAPP = () => {
Object.assign(renderPlayer, { ...player, x: renderPlayer.x, y: renderPlayer.y});
}
} else {
renderPlayersArr.push({ ...player });
renderPlayers.push({ ...player });
if (player.addr === curAddr) {
setOffset(calculateOffset(player));
}
console.log(`load player ${player.name}`)
}
});
// filter non-existent player
renderPlayersArr = renderPlayersArr.filter((player) => {
const hasFound = players.find((p) => p.addr === player.addr);
renderPlayersRef.current = renderPlayers.filter((player) => {
const hasFound = validPlayer.find((p) => p.addr === player.addr);
if (!hasFound) {
console.log(`removed player ${player.name}`)
}
return hasFound;
});
setRenderPlayers(renderPlayersArr);
setPlayerUpdateTime(Date.now());
// setRenderPlayers(renderPlayersArr);
exeMoveTasks();
}, [playersCache]);

Expand Down Expand Up @@ -117,12 +124,14 @@ const PIXIAPP = () => {
updatePlayerPosition(movingPlayer, linePath[index]);
movingPlayer.action = 'run';
movingPlayer.moving = true;
setRenderPlayers([...renderPlayers]);
// setRenderPlayers([...renderPlayers]);
setPlayerUpdateTime(Date.now());
index++;
if (index >= linePath.length) {
movingPlayer.action = 'idle';
movingPlayer.moving = false;
setRenderPlayers([...renderPlayers]);
// setRenderPlayers([...renderPlayers]);
setPlayerUpdateTime(Date.now());
clearInterval(interval);
onFinish?.()
}
Expand Down Expand Up @@ -175,15 +184,13 @@ const PIXIAPP = () => {
}
return [];
})
if (isDelivery(coordinate)) {
let path = paths[paths.length - 1];
if (path.x === 4 && path.y === 5) {
onMoveToDelivery();
}
if (isDelivery(paths[paths.length - 1])) {
onMoveToDelivery();
} else {
tryHunt();
}
setRenderPlayers([...renderPlayers]);
// setRenderPlayers([...renderPlayers]);
setPlayerUpdateTime(Date.now());
});

}
Expand All @@ -208,6 +215,10 @@ const PIXIAPP = () => {
setMenuVisible(false);
break;
case 'click':
// it will ignore the event when click delivery
if (isDelivery(coordinate)) {
return;
}
targetChests = treasureChest.filter(item => item.x === coordinate.x && item.y === coordinate.y);
if (targetChests.length > 0 && getDistance(curPlayer, coordinate) < 2) {
openTreasureChest(targetChests[0].id);
Expand Down Expand Up @@ -280,7 +291,7 @@ const PIXIAPP = () => {
data={treasureChest}
openingBox={openingBox}
/>
<PIXIPlayers data={renderPlayers} huntingPlayerId={huntingPlayerId}/>
<PIXIPlayers data={renderPlayers} huntingPlayerId={huntingPlayerId} playerUpdateTime={playerUpdateTime}/>
<PIXIFog position={curPlayer ? [curPlayer.x, curPlayer.y] : [4, 5]}/>
</Container>
</Stage>
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const Player = (props: IPlayer) => {
const { username, addr, equip, gem = 0, toward, waiting, x, y } = props;
const { curAddr } = useContext(GameContext);

// console.log(addr, curAddr, 'addr curid')
return (
<div>
{
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/Rank/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface IProps {
const Rank = (props: IProps) => {

const { data, curId } = props;
console.log(data)
const curIndex = data.findIndex(item => item.id === 1);
const [visible, setVisible] = useState(false);

Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/Typewriter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function Typewriter({ text, typingSpeed, step, name }) {
}, [text, typingSpeed, currentIndex]);

useEffect(() => {
console.log(1)
setDisplayText('');
setCurrentIndex(0);
}, [step]);
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/components/UserInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React, { useEffect, useState } from 'react';
import './styles.scss';
import UserPackage from '@/components/UserPackage';
import Appearance from '@/components/Appearance';
import * as PIXI from 'pixi.js';
import { Stage } from '@pixi/react';
import Player, { IPlayer } from '@/components/PIXIPlayers/Player';
import { MapConfig } from '@/config/map';
import Equipment from '@/components/Equipment';
const { cellSize } = MapConfig;
import defaultFoot from '@/assets/default-equip/Foot.png';
import defaultHand from '@/assets/default-equip/hand1.png';
import defaultNeck from '@/assets/default-equip/neck.png';
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ export const MapConfig = {
spriteCellSize: 16,
width: MAP_CFG[0].length,
height: MAP_CFG.length,
maxAnimateDistance: 7,
}

1 change: 0 additions & 1 deletion packages/client/src/hooks/useMerkel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const useMerkel = (mapData) => {
keccak256,
{ sortPairs: true }
);
// console.log(merkel.current?.getHexRoot(), 'root')
}, [mapData]);

return formatMovePath;
Expand Down
14 changes: 8 additions & 6 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SetupNetworkResult } from "./setupNetwork";
import eventEmitter from '../utils/eventEmitter';
import { message } from 'antd';

import { delay } from '../utils/delay';

export type SystemCalls = ReturnType<typeof createSystemCalls>;

let wait = false;
Expand Down Expand Up @@ -42,13 +44,10 @@ export function createSystemCalls(
}

const transfer = async (addr: any, transferData: any) => {
console.log('transfer', new Date().getTime());
try {
const tx = await worldContract.write.transfer([addr, ...transferData]);
await waitForTransaction(tx);
console.log('transfer success', new Date().getTime(), tx);
} catch (error) {
console.log('transfer', error);
message.error(error.cause.reason || error.cause.details);
}
}
Expand All @@ -64,7 +63,6 @@ export function createSystemCalls(
const tx = await worldContract.write.move([steps]);
await waitForTransaction(tx);
const receipt = await publicClient.getTransactionReceipt({ hash: tx });
console.log(receipt)
// let receipt = r.receipt
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
Expand All @@ -79,11 +77,10 @@ export function createSystemCalls(
};

const selectBothNFT = async (userTokenId: any, lootTokenId: any, address: any) => {
console.log('selectBothNFT', new Date().getTime());
try {
const tx = await worldContract.write.selectBothNFT([userTokenId, lootTokenId]);
await waitForTransaction(tx);
console.log('selectBothNFT success', new Date().getTime(), tx);
await delay(300)
return {
playerData: useStore.getState().getValue(tables.PlayerParams, { addr: address }),
lootData: useStore.getState().getValue(tables.LootList1, { addr: address })
Expand Down Expand Up @@ -182,6 +179,7 @@ export function createSystemCalls(
eventEmitter.emit('log', log)
console.log('revealBox success', new Date().getTime(), tx);
wait = false
await delay(300)
return useStore.getState().getValue(tables.BoxList, { boxId })
} catch (error) {
console.log(error)
Expand All @@ -207,6 +205,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success'
}
Expand Down Expand Up @@ -262,6 +261,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success',
data: useStore.getState().getValue(tables.BattleList, { battleId })
Expand Down Expand Up @@ -294,6 +294,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success',
data: useStore.getState().getValue(tables.BattleList, { battleId })
Expand Down Expand Up @@ -326,6 +327,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return useStore.getState().getValue(tables.BattleList, { battleId })
} catch (error) {
log.type = 'error'
Expand Down
Loading

0 comments on commit 130f5db

Please sign in to comment.