-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-map' of https://github.com/Mississippi-Labs/mississ…
…ippi into dev-map
- Loading branch information
Showing
20 changed files
with
4,097 additions
and
449 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
.mi-map-content { | ||
border: 1px solid; | ||
width: $cellSize * 24; | ||
font-size: 0; | ||
} | ||
|
||
.mi-map-row { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.mi-player { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.player-body { | ||
flex: 1; | ||
//background: url(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { MerkleTree } from 'merkletreejs'; | ||
import { solidityKeccak256, keccak256 } from 'ethers/lib/utils'; | ||
import { Buffer } from 'buffer'; | ||
|
||
|
||
const useMerkel = (mapData) => { | ||
|
||
const convertToLeafs = (mapData) => { | ||
const result = []; | ||
for (let y = 0; y < mapData.length; y++) { | ||
for (let x = 0; x < mapData[y].length; x++) { | ||
result.push({ x, y, value: mapData[y][x] }); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
const leafs = useRef([]); | ||
|
||
const merkel = useRef<MerkleTree | null>(null); | ||
|
||
const getProof = (x, y) => { | ||
const leaf = generateLeaf(x, y, 1); | ||
return merkel.current!.getHexProof(leaf); | ||
} | ||
|
||
// 通过本函数将地图初始化为默克尔树节点的字符串数组,每个字符串的格式为"x,y-value" | ||
// 其中value为0或1,表示该位置是否可以走,默认0不可走,1以及以后数字可以约定分别代表不同的可行性 | ||
const generateLeaf = (x, y, value) => { | ||
|
||
return Buffer.from( | ||
solidityKeccak256( | ||
["uint16", "string", "uint16", "string", "uint8"], | ||
[x, ",", y, ",", value] | ||
).slice(2), | ||
"hex" | ||
); | ||
} | ||
|
||
const formatMovePath = (paths) => { | ||
const steps = paths.map(({ x, y }) => [x, y]); | ||
const result = []; | ||
for (let i = 0; i < steps.length; i++) { | ||
const proof = getProof(steps[i][0], steps[i][1]); | ||
result.push([steps[i][0], steps[i][1], proof]); | ||
} | ||
return result; | ||
} | ||
|
||
useEffect(() => { | ||
if (mapData.length === 0) { | ||
return; | ||
} | ||
leafs.current = convertToLeafs(mapData); | ||
merkel.current = new MerkleTree( | ||
leafs.current.map((info) => generateLeaf(info.x, info.y, info.value)), | ||
keccak256, | ||
{ sortPairs: true } | ||
); | ||
}, [mapData]); | ||
|
||
return formatMovePath; | ||
} | ||
|
||
export default useMerkel; |
Oops, something went wrong.