Skip to content

Commit

Permalink
CI: add git hook and lint (#71)
Browse files Browse the repository at this point in the history
* build: add dependency for hooks, lint

* style: prettier *.ts

* style: eslint *.ts

* style: forge fmt sol

* style: lint tsx

* refactor: rm forge eslint
  • Loading branch information
noyyyy authored Aug 6, 2023
1 parent a1788f1 commit 6da9fd1
Show file tree
Hide file tree
Showing 60 changed files with 3,044 additions and 2,838 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
types
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
]
}
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
node_modules
packages/contracts/node_modules

# vscode
.vscode
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
types
Empty file added .prettierrc
Empty file.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"solidity.monoRepoSupport": true
"solidity.monoRepoSupport": true,
"editor.formatOnSave": true,
"solidity.formatter": "forge"
}
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,38 @@
"prepare": "(forge --version || pnpm foundry:up)",
"test": "pnpm recursive run test"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*.ts": [
"prettier"
],
"*.tsx": [
"prettier"
],
"*.sol": [
"forge fmt"
]
},
"devDependencies": {
"@latticexyz/cli": "2.0.0-alpha.1.251+deda0235",
"@typescript-eslint/eslint-plugin": "5.46.1",
"@typescript-eslint/parser": "5.46.1",
"concurrently": "^8.0.1",
"eslint": "8.29.0",
"git-cz": "^4.9.0",
"lint-staged": "^13.2.3",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"simple-git-hooks": "^2.9.0",
"typescript": "^4.9.5"
},
"engines": {
"node": "18.x",
"pnpm": "8.x"
},
"dependencies": {
"git-cz": "^4.9.0"
"eslint-plugin-react": "7.31.11"
}
}
}
23 changes: 5 additions & 18 deletions packages/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ import Feedback from "./ui/Feedback";

export const App = () => {
const {
components: {
PlayerGlobal,
},
components: { PlayerGlobal },
systemCalls: { surrender },
network: {
playerEntity,
},
network: { playerEntity },
} = useMUD();

const playerObj = useComponentValue(PlayerGlobal, playerEntity);

const isPlay = playerObj?.status == 1;


return (
<>
{isPlay ? <AutoChess /> : <JoinGame />}
Expand All @@ -31,19 +26,11 @@ export const App = () => {
className="flex items-center px-3 py-1 mt-1 text-white bg-gray-500 rounded hover:bg-gray-600"
onClick={() => surrender()}
>
<svg
className="w-5 h-5"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
d="M17.114,3.923h-4.589V2.527c0-0.252-0.207-0.459-0.46-0.459H7.935c-0.252,0-0.459,0.207-0.459,0.459v1.396h-4.59c-0.252,0-0.459,0.205-0.459,0.459c0,0.252,0.207,0.459,0.459,0.459h1.51v12.732c0,0.252,0.207,0.459,0.459,0.459h10.29c0.254,0,0.459-0.207,0.459-0.459V4.841h1.511c0.252,0,0.459-0.207,0.459-0.459C17.573,4.127,17.366,3.923,17.114,3.923M8.394,2.527c0-0.253,0.205-0.459,0.459-0.459h4.059c0.252,0,0.459,0.206,0.459,0.459v1.396h-4.059V2.527z M16.971,16.015c0,0.253-0.205,0.459-0.459,0.459H5.502c-0.253,0-0.459-0.206-0.459-0.459V4.841h11.469V16.015z M13.882,8.732c0-0.253,0.205-0.459,0.459-0.459c0.253,0,0.458,0.206,0.458,0.459v4.059c0,0.252-0.205,0.459-0.458,0.459c-0.253,0-0.459-0.207-0.459-0.459V8.732z M12.948,13.917c0.124-0.125,0.124-0.329,0-0.453l-1.918-1.918c-0.124-0.125-0.33-0.125-0.452,0s-0.125,0.33,0,0.453l1.918,1.918c0.124,0.125,0.33,0.125,0.452,0S12.848,14.042,12.948,13.917z"
/>
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
<path d="M17.114,3.923h-4.589V2.527c0-0.252-0.207-0.459-0.46-0.459H7.935c-0.252,0-0.459,0.207-0.459,0.459v1.396h-4.59c-0.252,0-0.459,0.205-0.459,0.459c0,0.252,0.207,0.459,0.459,0.459h1.51v12.732c0,0.252,0.207,0.459,0.459,0.459h10.29c0.254,0,0.459-0.207,0.459-0.459V4.841h1.511c0.252,0,0.459-0.207,0.459-0.459C17.573,4.127,17.366,3.923,17.114,3.923M8.394,2.527c0-0.253,0.205-0.459,0.459-0.459h4.059c0.252,0,0.459,0.206,0.459,0.459v1.396h-4.059V2.527z M16.971,16.015c0,0.253-0.205,0.459-0.459,0.459H5.502c-0.253,0-0.459-0.206-0.459-0.459V4.841h11.469V16.015z M13.882,8.732c0-0.253,0.205-0.459,0.459-0.459c0.253,0,0.458,0.206,0.458,0.459v4.059c0,0.252-0.205,0.459-0.458,0.459c-0.253,0-0.459-0.207-0.459-0.459V8.732z M12.948,13.917c0.124-0.125,0.124-0.329,0-0.453l-1.918-1.918c-0.124-0.125-0.33-0.125-0.452,0s-0.125,0.33,0,0.453l1.918,1.918c0.124,0.125,0.33,0.125,0.452,0S12.848,14.042,12.948,13.917z" />
</svg>

<span className="ml-2">
Reset
</span>
<span className="ml-2">Reset</span>
</button>
</div>
<Feedback />
Expand Down
62 changes: 27 additions & 35 deletions packages/client/src/hooks/useBlockNumber.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,77 @@
import { useState, useEffect, useRef } from 'react';
import useChessboard from './useChessboard'


import { useState, useEffect, useRef } from "react";
import useChessboard from "./useChessboard";

const useBlockNumber = () => {

const { getCurrentBlockNumber, roundInterval, startFrom, autoBattleFn, BoardList } = useChessboard()
const {
getCurrentBlockNumber,
roundInterval,
startFrom,
autoBattleFn,
BoardList,
} = useChessboard();

const [blockNumber, setBlockNumber] = useState<number>();
const [startBlockNumber, setStartBlockNumber] = useState<number>();

const [isCalculating, setIsCalculating] = useState(false)

const [isCalculating, setIsCalculating] = useState(false);

useEffect(() => {

const initStart = async () => {
const number = await getCurrentBlockNumber();
const startTime = Number(startFrom) + Number(roundInterval)
const Timeleft = startTime - number
console.log('init battle', Timeleft)
const startTime = Number(startFrom) + Number(roundInterval);
const Timeleft = startTime - number;
console.log("init battle", Timeleft);

if (Timeleft <= 0) {
await autoBattleFn();
setIsCalculating(true)
setIsCalculating(true);
}
}
initStart()

}, [])
};
initStart();
}, []);

useEffect(() => {

const interval = setInterval(async () => {
const number = await getCurrentBlockNumber();
const startTime = Number(startFrom) + Number(roundInterval)
const Timeleft = startTime - number
setStartBlockNumber(Timeleft)
const startTime = Number(startFrom) + Number(roundInterval);
const Timeleft = startTime - number;
setStartBlockNumber(Timeleft);
setBlockNumber(number);
if (Timeleft == 0) {
await autoBattleFn();
setIsCalculating(true)
setIsCalculating(true);
}

if (Timeleft < 0 && !isCalculating) {
await autoBattleFn();
setIsCalculating(true)
setIsCalculating(true);
}


}, 1000);

return () => clearInterval(interval);
}, [startFrom, roundInterval, getCurrentBlockNumber,isCalculating])
}, [startFrom, roundInterval, getCurrentBlockNumber, isCalculating]);

useEffect(() => {
let calculateInterval: any;

if ((BoardList?.status == 1) && isCalculating) {
if (BoardList?.status == 1 && isCalculating) {
calculateInterval = setInterval(async () => {
await autoBattleFn();
}, 1500);
}


return () => {
if (calculateInterval) {
clearInterval(calculateInterval);
}
};
}, [isCalculating, BoardList?.status]);



return {
blockNumber,
roundInterval,
startBlockNumber
}

}

startBlockNumber,
};
};

export default useBlockNumber;
Loading

0 comments on commit 6da9fd1

Please sign in to comment.