mirror of
https://github.com/chase-manning/pokemon-js.git
synced 2025-11-03 01:18:58 +00:00
🚀 add support for talking quests
This commit is contained in:
parent
9ef2cc396f
commit
875200fb4d
1 changed files with 22 additions and 1 deletions
|
|
@ -1,14 +1,18 @@
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { selectMapId, selectPos } from "../state/gameSlice";
|
||||
import { selectDirection, selectMapId, selectPos } from "../state/gameSlice";
|
||||
import { useActiveMapQuests } from "../app/use-quests";
|
||||
import { useEffect } from "react";
|
||||
import { showTextThenAction } from "../state/uiSlice";
|
||||
import useEvent from "../app/use-event";
|
||||
import { Event } from "../app/emitter";
|
||||
import { directionModifier } from "../app/map-helper";
|
||||
|
||||
const QuestHandler = () => {
|
||||
const dispatch = useDispatch();
|
||||
const mapId = useSelector(selectMapId);
|
||||
const quests = useActiveMapQuests(mapId);
|
||||
const pos = useSelector(selectPos);
|
||||
const facing = useSelector(selectDirection);
|
||||
|
||||
useEffect(() => {
|
||||
quests.forEach((quest) => {
|
||||
|
|
@ -25,6 +29,23 @@ const QuestHandler = () => {
|
|||
});
|
||||
}, [quests, pos, dispatch]);
|
||||
|
||||
useEvent(Event.A, () => {
|
||||
const mod = directionModifier(facing);
|
||||
const questPos = { x: pos.x + mod.x, y: pos.y + mod.y };
|
||||
quests.forEach((quest) => {
|
||||
if (quest.trigger !== "talk") return;
|
||||
const yPos = quest.positions[questPos.y];
|
||||
if (!yPos) return;
|
||||
if (!yPos.includes(questPos.x)) return;
|
||||
dispatch(
|
||||
showTextThenAction({
|
||||
text: quest.text,
|
||||
action: () => quest.action(),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue