-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persona / Launcher Integration (#18)
* refactor(ri/client): fix up the interface for action creators * feat(ri): hook ri up to launcher and persona * fix(ri): use 31337 as local chain id everywhere * feat: integrate persona and player entity when spawning * feat: join game with persona integrated * fix(solecs,ri): fix remappings * fix(ri/client): add lodash to ri client * feat(contract): check entity owner when moving * fix(ri/contracts): fix Diamond upgrade hardhat task and make it faster * fix(ri/contract): remove garbage function Co-authored-by: ludens <ludens@lattice.xyz>
- Loading branch information
Showing
33 changed files
with
300 additions
and
188 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { spawnCreatureFunc } from "./spawnCreature"; | ||
export { moveEntityFunc } from "./moveEntity"; | ||
export { joinGame } from "./joinGame"; | ||
export { moveEntity } from "./moveEntity"; |
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,37 @@ | ||
import { WorldCoord } from "@latticexyz/phaserx/src/types"; | ||
import { getEntitiesWithValue } from "@latticexyz/recs"; | ||
import { getPlayerEntity } from "@latticexyz/std-client"; | ||
import { NetworkLayer } from "../../Network"; | ||
import { EntityTypes } from "../../Network/types"; | ||
import { ActionSystem } from "../types"; | ||
|
||
export function joinGame(network: NetworkLayer, actions: ActionSystem, targetPosition: WorldCoord) { | ||
const { Position, Persona } = network.components; | ||
|
||
actions.add({ | ||
id: `spawn ${Math.random()}`, | ||
components: { Position, Persona }, | ||
requirement: ({ Position, Persona }) => { | ||
const blockingEntities = getEntitiesWithValue(Position, targetPosition); | ||
if (blockingEntities.size !== 0) return null; | ||
|
||
if (!network.personaId) { | ||
console.warn("No persona ID found, canceling spawn attempt"); | ||
return null; | ||
} | ||
|
||
const playerEntity = getPlayerEntity(Persona, network.personaId); | ||
if (playerEntity) { | ||
console.warn("Player already spawned, canceling spawn."); | ||
return null; | ||
} | ||
|
||
return true; | ||
}, | ||
updates: () => [], | ||
execute: () => { | ||
console.log(`spawning entityType: ${EntityTypes.Creature} at ${JSON.stringify(targetPosition)}`); | ||
network.api.joinGame(targetPosition, EntityTypes.Creature); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.