Skip to content

Commit 13ffd6c

Browse files
committed
render selected quest rewards
1 parent 010ca16 commit 13ffd6c

File tree

2 files changed

+100
-75
lines changed

2 files changed

+100
-75
lines changed

src/Quest.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,19 @@ export const quarks = {
401401
'You have proved your worth for the Master of Arms, and he gives you one of his rare weapons.',
402402
/* prettier-ignore */
403403
choicerewards: [
404-
5109, 5124,
405-
5210, 5222,
406-
5308, 5324,
407-
5407, 5423,
408-
5509, 5523,
409-
5607, 5621,
410-
5708, 5723,
411-
5809, 5822,
412-
5909, 5924,
413-
6008, 6025,
414-
6107, 6126,
415-
6206, 6223,
416-
],
404+
5109, 5124,
405+
5210, 5222,
406+
5308, 5324,
407+
5407, 5423,
408+
5509, 5523,
409+
5607, 5621,
410+
5708, 5723,
411+
5809, 5822,
412+
5909, 5924,
413+
6008, 6025,
414+
6107, 6126,
415+
6206, 6223,
416+
],
417417
info: 'Fight the Master of Arms at the Proving Grounds!',
418418
},
419419
pgshard: {
@@ -638,7 +638,7 @@ export const quarks = {
638638
hp: 400,
639639
markpower: 3,
640640
drawpower: 2,
641-
cardreward: '0171r01785017bf017ea017hj017nm017qv01813018pi',
641+
cardreward: '0171r01785017bf017ea017hj017nm017qv01813',
642642
info: 'The AI has taken control of Serprex’s account and gone berserk. It has a power beyond a demigod!',
643643
wintext:
644644
'You defeat the AI menace and restore Serprex’s account to their rightful place. Phew!',
@@ -728,21 +728,6 @@ export const root = {
728728
],
729729
};
730730

731-
export function extractRewards(obj) {
732-
for (const key in obj) {
733-
console.log(typeof obj[key])
734-
if (typeof obj[key] === 'object' && obj[key] !== null) {
735-
extractRewards(obj[key]);
736-
} else if (key === 'cardreward' || key === 'choicerewards') {
737-
return '+Card'
738-
//TODO: break down card reward options into onHover
739-
// obj[key].cardreward ? '+Cards' : '+'+obj[key].goldreward+'$';
740-
} else if (key === 'goldreward') {
741-
return '+'+obj[key];
742-
}
743-
}
744-
}
745-
746731
export function mkQuestAi(quest, datafn) {
747732
const markpower = quest.markpower ?? 1;
748733
const drawpower = quest.drawpower ?? 1;

src/views/Quest.jsx

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,83 @@
11
import { createMemo } from 'solid-js';
2+
3+
import Cards from '../Cards.js';
24
import * as Quest from '../Quest.js';
5+
import CardImage from '../Components/CardImage.jsx';
36
import ExitBtn from '../Components/ExitBtn.jsx';
47
import Text from '../Components/Text.jsx';
58
import * as store from '../store.jsx';
9+
import { decodedeck } from '../etgutil.js';
610

7-
function QuestButton(props) {
11+
export function QuestRewards(props) {
12+
const quest = createMemo(() => {
13+
let quest = props.quest;
14+
if (!quest) return null;
15+
while (quest.autonext) quest = quest.autonext;
16+
return quest;
17+
});
818
return (
919
<>
10-
<span
11-
style={{
12-
position: 'absolute',
13-
left: `${props.x}px`,
14-
top: `${props.y}px`,
15-
color: `#${
16-
typeof props.area === 'string' && !props.user.quests[props.area] ?
17-
'f'
18-
: 'a'
19-
}${props.sel ? 'ff' : 'aa'}`,
20-
}}
21-
onClick={props.onClick}>
22-
{typeof props.area === 'string' ?
23-
Quest.quarks[props.area].name
24-
: props.area.name}
25-
</span>
26-
{Quest.extractRewards(Quest.quarks[props.area]) && !props.user.quests[props.area] && (
27-
<span
28-
style={{
29-
position: 'absolute',
30-
left: `${props.x + 200}px`,
31-
top: `${props.y}px`,
32-
}}>
33-
{Quest.extractRewards(Quest.quarks[props.area])}
34-
{Quest.extractRewards(Quest.quarks[props.area]) !== '+Card' && (
35-
<span className="ico gold" />
20+
{quest()?.choicerewards && (
21+
<div style="position:absolute;left:750px;top:156px;display:flex;height:200px;flex-direction:column">
22+
<div>Choice</div>
23+
{Array.isArray(quest()?.choicerewards) && (
24+
<Index each={quest()?.choicerewards}>
25+
{(reward, i) => (
26+
<CardImage
27+
style={{ position: 'absolute', top: i * 20 + 'px' }}
28+
card={Cards.Codes[reward()]}
29+
/>
30+
)}
31+
</Index>
3632
)}
37-
</span>
33+
{!Array.isArray(quest()?.choicerewards) && quest()?.choicerewards}
34+
</div>
35+
)}
36+
{quest()?.cardreward && (
37+
<div style="position:absolute;left:750px;top:156px;display:flex;height:200px;flex-direction:column">
38+
<div>Cards</div>
39+
<Index each={decodedeck(quest()?.cardreward)}>
40+
{(code, i) => (
41+
<CardImage
42+
style={{ position: 'absolute', top: i * 20 + 'px' }}
43+
card={Cards.Codes[code()]}
44+
/>
45+
)}
46+
</Index>
47+
</div>
48+
)}
49+
{quest()?.goldreward && (
50+
<div style="position:absolute;left:750px;top:156px">
51+
{quest()?.goldreward}
52+
<span class="ico gold" />
53+
</div>
3854
)}
3955
</>
4056
);
4157
}
4258

43-
export default function QuestView(props) {
59+
function QuestButton(props) {
60+
return (
61+
<span
62+
style={{
63+
position: 'absolute',
64+
left: `${props.x}px`,
65+
top: `${props.y}px`,
66+
color: `#${
67+
typeof props.area === 'string' && !props.quests[props.area] ?
68+
'f'
69+
: 'a'
70+
}${props.sel ? 'ff' : 'aa'}`,
71+
}}
72+
onClick={props.onClick}>
73+
{typeof props.area === 'string' ?
74+
Quest.quarks[props.area].name
75+
: props.area.name}
76+
</span>
77+
);
78+
}
79+
80+
export default function QuestView() {
4481
const rx = store.useRx();
4582
const questInfo = createMemo(() => {
4683
const questAreas = [],
@@ -50,16 +87,18 @@ export default function QuestView(props) {
5087
let y = 162;
5188
for (let i = 0; i < qbag.children.length; i++) {
5289
const area = qbag.children[i];
53-
if (typeof area === 'string') {
54-
const quark = Quest.quarks[area];
55-
if (!Quest.requireQuest(quark, rx.user)) continue;
90+
if (
91+
typeof area === 'string' &&
92+
!Quest.requireQuest(Quest.quarks[area], rx.user)
93+
) {
94+
continue;
5695
}
5796
questAreas.push(
5897
<QuestButton
59-
x={8 + qi * 177}
98+
x={8 + qi * 180}
6099
y={y}
61100
area={area}
62-
user={rx.user}
101+
quests={rx.user.quests}
63102
onClick={() => {
64103
const newquest = quest.slice(0, qi);
65104
newquest[qi] = i;
@@ -82,26 +121,27 @@ export default function QuestView(props) {
82121
<>
83122
<div
84123
class="bgbox"
85-
style="position:absolute;left:8px;top:8px;width:880px;height:108px"
86-
/>
87-
<ExitBtn x={750} y={120} />
88-
<div style="position:absolute;left:26px;top:26px;max-width:850px">
124+
style="position:absolute;left:8px;top:8px;width:880px;height:108px;padding-left:15px;padding-top:15px">
89125
<Text
90126
text={
91127
questInfo().selectedQuest?.info ??
92128
"Click list items to see quest lines, & FIGHT button to challenge them!\nNames in red are quests you haven't completed."
93129
}
94130
/>
95131
</div>
132+
<ExitBtn x={750} y={120} />
96133
{questInfo().selectedQuest?.key && (
97-
<input
98-
type="button"
99-
value="Fight!"
100-
style="position:absolute;left:8px;top:120px"
101-
onClick={() =>
102-
store.navGame(Quest.mkQuestAi(questInfo().selectedQuest))
103-
}
104-
/>
134+
<>
135+
<input
136+
type="button"
137+
value="Fight!"
138+
style="position:absolute;left:8px;top:120px"
139+
onClick={() =>
140+
store.navGame(Quest.mkQuestAi(questInfo().selectedQuest))
141+
}
142+
/>
143+
<QuestRewards quest={Quest.quarks[questInfo().selectedQuest.key]} />
144+
</>
105145
)}
106146
{questInfo().questAreas}
107147
</>

0 commit comments

Comments
 (0)