-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
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,12 @@ | ||
import { defineComponent, Metadata, Type, World } from "@latticexyz/recs"; | ||
|
||
export function defineVoxelCoordComponent<M extends Metadata>( | ||
world: World, | ||
options?: { id?: string; metadata?: M; indexed?: boolean } | ||
) { | ||
return defineComponent<{ x: Type.Number; y: Type.Number; z: Type.Number }, M>( | ||
world, | ||
{ x: Type.Number, y: Type.Number, z: Type.Number }, | ||
options | ||
); | ||
} |
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
27 changes: 27 additions & 0 deletions
27
packages/std-contracts/src/components/Uint32ArrayComponent.sol
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,27 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity >=0.8.0; | ||
import "solecs/Component.sol"; | ||
|
||
contract Uint32ArrayComponent is Component { | ||
constructor(address world, uint256 id) Component(world, id) {} | ||
|
||
function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { | ||
keys = new string[](1); | ||
values = new LibTypes.SchemaValue[](1); | ||
|
||
keys[0] = "value"; | ||
values[0] = LibTypes.SchemaValue.UINT32_ARRAY; | ||
} | ||
|
||
function set(uint256 entity, uint32[] memory value) public { | ||
set(entity, abi.encode(value)); | ||
} | ||
|
||
function getValue(uint256 entity) public view returns (uint32[] memory) { | ||
return abi.decode(getRawValue(entity), (uint32[])); | ||
} | ||
|
||
function getEntitiesWithValue(uint32[] memory value) public view returns (uint256[] memory) { | ||
return getEntitiesWithValue(abi.encode(value)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/std-contracts/src/components/VoxelCoordComponent.sol
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,40 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity >=0.8.0; | ||
import "solecs/Component.sol"; | ||
|
||
struct VoxelCoord { | ||
int32 x; | ||
int32 y; | ||
int32 z; | ||
} | ||
|
||
contract VoxelCoordComponent is Component { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
constructor(address world, uint256 id) Component(world, id) {} | ||
|
||
function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { | ||
keys = new string[](3); | ||
values = new LibTypes.SchemaValue[](3); | ||
|
||
keys[0] = "x"; | ||
values[0] = LibTypes.SchemaValue.INT32; | ||
|
||
keys[1] = "y"; | ||
values[1] = LibTypes.SchemaValue.INT32; | ||
|
||
keys[2] = "z"; | ||
values[2] = LibTypes.SchemaValue.INT32; | ||
} | ||
|
||
function set(uint256 entity, VoxelCoord calldata value) public { | ||
set(entity, abi.encode(value)); | ||
} | ||
|
||
function getValue(uint256 entity) public view returns (VoxelCoord memory) { | ||
(int32 x, int32 y, int32 z) = abi.decode(getRawValue(entity), (int32, int32, int32)); | ||
return VoxelCoord(x, y, z); | ||
} | ||
|
||
function getEntitiesWithValue(VoxelCoord calldata coord) public view returns (uint256[] memory) { | ||
return getEntitiesWithValue(abi.encode(coord)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -36,3 +36,9 @@ export type Coord = { | |
x: number; | ||
y: number; | ||
}; | ||
|
||
export type VoxelCoord = { | ||
x: number; | ||
y: number; | ||
z: number; | ||
}; |
😲