Skip to content

Commit

Permalink
feat: add 3d components
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Jul 28, 2022
1 parent 5cacc92 commit d230339
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const PositionFilterButton: React.FC<{
if (!selectingPosition) return;

function onMouseDown() {
if (!input) return;
const pointer = input.activePointer;
const pos = { x: pointer.worldX, y: pointer.worldY };
const worldCoord = pixelCoordToTileCoord(pos, 16, 16);
Expand Down
2 changes: 1 addition & 1 deletion packages/ecs-browser/src/QueryBuilder/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const QueryBuilder = ({
editQuery={editQuery}
hoverHighlightComponent={hoverHighlightComponent}
queryInputRef={queryInputRef}
input={(layers.phaser as any).scenes.Main.phaserScene.input}
input={(layers.phaser as any)?.scenes.Main.phaserScene.input}
/>
<h3>Filter by Component</h3>
<QueryShortcutContainer style={{ margin: "8px auto" }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export class HueTintAndOutlineFXPipeline extends Phaser.Renderer.WebGL.Pipelines.SpriteFXPipeline {
const SpritePipeline = Phaser.Renderer.WebGL.Pipelines.SpriteFXPipeline || Object;
export class HueTintAndOutlineFXPipeline extends SpritePipeline {
public static readonly KEY = "HueTintFXPipeline";

private _tintColor = new Phaser.Display.Color();
Expand Down
12 changes: 12 additions & 0 deletions packages/std-client/src/components/VoxelCoordComponent.ts
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
);
}
1 change: 1 addition & 0 deletions packages/std-client/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { defineBoolComponent } from "./BoolComponent";
export { defineCoordComponent } from "./CoordComponent";
export { defineStringComponent } from "./StringComponent";
export { defineActionComponent } from "./ActionComponent";
export { defineVoxelCoordComponent } from "./VoxelCoordComponent";
27 changes: 27 additions & 0 deletions packages/std-contracts/src/components/Uint32ArrayComponent.sol
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 packages/std-contracts/src/components/VoxelCoordComponent.sol
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.

Copy link
@Kooshaba

Kooshaba Jul 28, 2022

Contributor

😲

This comment has been minimized.

Copy link
@alvrs

alvrs Jul 28, 2022

Author Member

🤫

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));
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export * from "./pack";
export * from "./CoordMap";
export * from "./eth";

export type { Cached, PromiseValue, ValueOf, Area, Coord } from "./types";
export type { Cached, PromiseValue, ValueOf, Area, Coord, VoxelCoord } from "./types";
6 changes: 6 additions & 0 deletions packages/utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ export type Coord = {
x: number;
y: number;
};

export type VoxelCoord = {
x: number;
y: number;
z: number;
};

0 comments on commit d230339

Please sign in to comment.