diff --git a/smart-turret/packages/client/src/App.tsx b/smart-turret/packages/client/src/App.tsx index a153faa..3b78460 100644 --- a/smart-turret/packages/client/src/App.tsx +++ b/smart-turret/packages/client/src/App.tsx @@ -1,3 +1,40 @@ +import { useCallback, useState } from "react"; +import { stash } from "./mud/stash"; +import { useStash } from "./mud/useStash"; +import { worldContract } from "./mud/worldContract"; + export const App = () => { - return <>Hello, World; + const [characterId, setCharacterId] = useState(0n); + + const guestList = useStash(stash, (state) => + Object.values(state.records.test.GuestList) + ); + + const addToGuestList = useCallback(() => { + worldContract.write.test__addToGuestList([characterId]); + }, [characterId]); + + return ( +
+
+ setCharacterId(BigInt(e.target.value))} + > + +
+
+ Guest list: + +
+
+ ); }; diff --git a/smart-turret/packages/contracts/mud.config.ts b/smart-turret/packages/contracts/mud.config.ts index 86a77d8..c03d2d1 100644 --- a/smart-turret/packages/contracts/mud.config.ts +++ b/smart-turret/packages/contracts/mud.config.ts @@ -2,5 +2,13 @@ import { defineWorld } from "@latticexyz/world"; export default defineWorld({ namespace: "test", - tables: {}, + tables: { + GuestList: { + schema: { + characterId: "uint256", + hasAccess: "bool", + }, + key: ["characterId"], + }, + }, }); diff --git a/smart-turret/packages/contracts/src/systems/GuestListSystem.sol b/smart-turret/packages/contracts/src/systems/GuestListSystem.sol new file mode 100644 index 0000000..88396b2 --- /dev/null +++ b/smart-turret/packages/contracts/src/systems/GuestListSystem.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { System } from "@latticexyz/world/src/System.sol"; +import { GuestList } from "../codegen/tables/GuestList.sol"; + +contract GuestListSystem is System { + function addToGuestList(uint256 characterId) public { + GuestList.setHasAccess(characterId, true); + } +} diff --git a/smart-turret/packages/contracts/src/systems/SmartTurretSystem.sol b/smart-turret/packages/contracts/src/systems/SmartTurretSystem.sol index fcb3659..3d5e84d 100644 --- a/smart-turret/packages/contracts/src/systems/SmartTurretSystem.sol +++ b/smart-turret/packages/contracts/src/systems/SmartTurretSystem.sol @@ -52,9 +52,8 @@ contract SmartTurretSystem is System { } } - //TODO: Implement the logic function _shouldShoot(SmartTurretTarget memory target) internal returns (bool) { - return true; + return !GuestList.getHasAccess(target.characterId); } /** diff --git a/smart-turret/packages/contracts/test/SmartTurretTest.t.sol b/smart-turret/packages/contracts/test/SmartTurretTest.t.sol index 54ba8a1..a1577a2 100644 --- a/smart-turret/packages/contracts/test/SmartTurretTest.t.sol +++ b/smart-turret/packages/contracts/test/SmartTurretTest.t.sol @@ -96,6 +96,8 @@ contract SmartTurretTest is MudTest { } function testInProximity() public { + world.test__addToGuestList(newTurretTarget.characterId); + TargetPriority[] memory returnTargetQueue = smartTurret.inProximity( smartTurretId, characterId, @@ -104,8 +106,7 @@ contract SmartTurretTest is MudTest { newTurretTarget ); - assertEq(returnTargetQueue.length, 2); + assertEq(returnTargetQueue.length, 1); assertEq(returnTargetQueue[0].target.characterId, previousTurretTarget.characterId); - assertEq(returnTargetQueue[1].target.characterId, newTurretTarget.characterId); } }