Skip to content

Commit

Permalink
Merge pull request latticexyz#1 from marvinmarnold/marvinmarnold/beat…
Browse files Browse the repository at this point in the history
…s-components

feat: SoundUriComponent and UploadSoundSystem
  • Loading branch information
0xPetra authored Oct 29, 2022
2 parents 97ebe59 + 70322bc commit eada15b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/client/src/layers/network/createNetworkLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export async function createNetworkLayer(config: GameConfig) {
systems["system.Catch"].executeTyped(coord);
}

function uploadSound(soundUri: string) {
systems["system.UploadSound"].executeTyped(soundUri);
}


// --- CONTEXT --------------------------------------------------------------------
const context = {
world,
Expand All @@ -58,7 +63,7 @@ export async function createNetworkLayer(config: GameConfig) {
startSync,
network,
actions,
api: { move, pickup },
api: { move, pickup, uploadSound },
dev: setupDevSystems(world, encoders, systems),
};

Expand Down
5 changes: 3 additions & 2 deletions packages/contracts/deploy.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"components": ["PositionComponent", "CarriedByComponent"],
"components": ["PositionComponent", "CarriedByComponent", "SoundUriComponent"],
"systems": [
{ "name": "ComponentDevSystem", "writeAccess": ["*"] },
{ "name": "MoveSystem", "writeAccess": ["PositionComponent"] },
{ "name": "CatchSystem", "writeAccess": ["PositionComponent", "CarriedByComponent"] }
{ "name": "CatchSystem", "writeAccess": ["PositionComponent", "CarriedByComponent"] },
{ "name": "UploadSoundSystem", "writeAccess": ["SoundUriComponent"] }
]
}
9 changes: 9 additions & 0 deletions packages/contracts/src/components/SoundUriComponent.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;
import "std-contracts/components/StringComponent.sol";

uint256 constant ID = uint256(keccak256("component.SoundUri"));

contract SoundUriComponent is StringComponent {
constructor(address world) StringComponent(world, ID) {}
}
24 changes: 24 additions & 0 deletions packages/contracts/src/systems/UploadSoundSystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import "solecs/System.sol";
import { IWorld } from "solecs/interfaces/IWorld.sol";
import { getAddressById } from "solecs/utils.sol";

import { SoundUriComponent, ID as SoundUriComponentID } from "../components/SoundUriComponent.sol";

uint256 constant ID = uint256(keccak256("system.UploadSound"));

contract UploadSoundSystem is System {
constructor(IWorld _world, address _components) System(_world, _components) {}

function execute(bytes memory arguments) public returns (bytes memory) {
(uint256 entity, string memory targetSoundUri) = abi.decode(arguments, (uint256, string));

SoundUriComponent soundComponent = SoundUriComponent(getAddressById(components, SoundUriComponentID));
soundComponent.set(entity, targetSoundUri);
}

function executeTyped(uint256 entity, string memory targetSound) public returns (bytes memory) {
return execute(abi.encode(entity, targetSound));
}
}

0 comments on commit eada15b

Please sign in to comment.