-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item investigation and pickup implemented.
No inventory viewing yet, though there is an inventory storing the items, items get removed from the map, and the player can investigate tiles to see what's there.
- Loading branch information
Showing
8 changed files
with
164 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { System, SystemQueries, World } from 'ecsy'; | ||
|
||
import { Game } from '../main.ts'; | ||
import * as Components from '../components.ts'; | ||
|
||
export class InventorySystem extends System { | ||
game: Game; | ||
|
||
constructor(world: World, game: Game) { | ||
super(world, game); | ||
this.game = game; | ||
} | ||
|
||
static queries: SystemQueries = { | ||
wantsToPickup: { | ||
components: [Components.AttemptToPickupItem], | ||
}, | ||
}; | ||
|
||
execute() { | ||
const { results } = this.queries.wantsToPickup; | ||
|
||
for (const entity of results) { | ||
const wantsToPickup = entity.getComponent(Components.AttemptToPickupItem)!; | ||
const inventory = entity.getComponent(Components.Inventory); | ||
const entityName = entity.getComponent(Components.Name)?.name || 'Someone'; | ||
const itemName = wantsToPickup.item.getComponent(Components.Name)?.name || 'something'; | ||
|
||
// we must have an inventory to pick something up | ||
if (inventory) { | ||
// add the item to inventory | ||
inventory.items.push(wantsToPickup.item); | ||
|
||
// remove it from the map | ||
wantsToPickup.item.removeComponent(Components.Position); | ||
|
||
// log the interaction | ||
this.game.log.addMessage(`${ entityName } picked up ${ itemName }.`); | ||
} | ||
|
||
// interaction is complete, remove the Attempt | ||
entity.removeComponent(Components.AttemptToPickupItem); | ||
} | ||
} | ||
} |
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