Skip to content

Commit 4721802

Browse files
committed
add debug block
with: - opened entry - facts in opened entry - allow to learn fact
1 parent 98435ef commit 4721802

File tree

5 files changed

+145
-7
lines changed

5 files changed

+145
-7
lines changed

frontend/src/App.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script module>
2+
import Debug from "@/components/Debug.svelte";
23
import FactsPanel from "@/components/FactsPanel.svelte";
34
import Sidebar from "@/components/Sidebar.svelte";
45
import Loading from "@/components/Loading.svelte";
@@ -18,7 +19,7 @@
1819
} from "@/lib/stores";
1920
import { get_facts_for } from "@/lib/data";
2021
import { init_i18n, t } from "@/lib/i18n";
21-
import { NEED_EXTENDED_SPOILER_FONT } from "./lib/language";
22+
import { NEED_EXTENDED_SPOILER_FONT } from "@/lib/language";
2223
</script>
2324

2425
<script>
@@ -65,4 +66,8 @@
6566
{:else if is_map_empty}
6667
<Popup>{$t("map-empty-popup")}</Popup>
6768
{/if}
69+
70+
{#if import.meta.env.DEV}
71+
<Debug />
72+
{/if}
6873
</main>

frontend/src/app.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ h1 {
6161
}
6262

6363
button,
64-
select {
64+
select,
65+
input[type="text"] {
6566
@extend %pointer;
6667

6768
border-radius: 8px;
@@ -74,6 +75,11 @@ select {
7475
transition: border-color 0.25s;
7576
}
7677

78+
input[type="text"] {
79+
cursor: text;
80+
padding: 0.6em;
81+
}
82+
7783
button:hover,
7884
select:hover {
7985
border-color: #646cff;
@@ -87,7 +93,8 @@ select:hover {
8793
button:focus,
8894
button:focus-visible,
8995
select:focus,
90-
select:focus-visible {
96+
select:focus-visible,
97+
input[type="text"]:focus {
9198
outline: 4px auto -webkit-focus-ring-color;
9299
}
93100

frontend/src/components/Debug.svelte

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<script module>
2+
import {
3+
get_all_save_keys,
4+
get_facts_ids_for,
5+
save_key_valid,
6+
} from "@/lib/data";
7+
import { OPENED_FACT, SAVE_FOUND } from "@/lib/stores";
8+
import {
9+
export_save_to_browser_url,
10+
get_save_from_browser_url,
11+
} from "@/lib/saves";
12+
</script>
13+
14+
<script>
15+
let fact_to_learn = $state("");
16+
let is_fact_to_learn_valid = $derived(save_key_valid(fact_to_learn));
17+
let is_fact_to_learn_already_learned = $derived(
18+
get_current_facts().has(fact_to_learn),
19+
);
20+
21+
function get_current_facts() {
22+
return get_save_from_browser_url(get_all_save_keys());
23+
}
24+
25+
function learn_fact() {
26+
let current_facts = get_current_facts();
27+
current_facts.add(fact_to_learn);
28+
export_save_to_browser_url(get_all_save_keys(), current_facts);
29+
}
30+
</script>
31+
32+
<div
33+
class="wrapper above-map-controls"
34+
class:hidden={!($OPENED_FACT || $SAVE_FOUND)}>
35+
{#if $OPENED_FACT}
36+
<div>
37+
<span>Current entry: {$OPENED_FACT}</span>
38+
</div>
39+
<div>
40+
<div>Facts:</div>
41+
<ul>
42+
{#each get_facts_ids_for($OPENED_FACT, true) as fact}
43+
<li class="mono" class:more-to-explore={fact.more_to_explore}>
44+
{fact.id}
45+
</li>
46+
{/each}
47+
</ul>
48+
</div>
49+
{/if}
50+
<div class="padding-top">
51+
{#if $SAVE_FOUND}
52+
<div>Learn fact:</div>
53+
<input type="text" bind:value={fact_to_learn} />
54+
<button
55+
disabled={fact_to_learn === "" ||
56+
!is_fact_to_learn_valid ||
57+
is_fact_to_learn_already_learned}
58+
onclick={learn_fact}>Learn</button>
59+
{#if fact_to_learn !== ""}
60+
<div class="padding-top">
61+
{#if is_fact_to_learn_valid}
62+
{#if is_fact_to_learn_already_learned}
63+
<i>Already learned</i>
64+
{/if}
65+
{:else}
66+
<i>Unknown save key</i>
67+
{/if}
68+
</div>
69+
{/if}
70+
{/if}
71+
</div>
72+
</div>
73+
74+
<style lang="scss">
75+
$color: #3280ff;
76+
77+
.wrapper {
78+
position: absolute;
79+
top: 0;
80+
right: 0;
81+
82+
height: auto;
83+
padding: 1em 1em;
84+
85+
background-color: var(--bg);
86+
border: 2px $color solid;
87+
}
88+
.padding-top {
89+
padding-top: 5px;
90+
}
91+
</style>

frontend/src/lib/data.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// i guess global state shouldn't work this way..
22
// todo: rewrite
3+
// todo: why set_ functions are async?
34

45
const RUMOR_REGEX = /_R\d+$/;
56

@@ -14,6 +15,10 @@ let tr = {};
1415
/** @type {Object<string, { entries: string[]; rumors: string[] }>} */
1516
let joined_rumors = {};
1617

18+
// used and filled only in debug
19+
let all_save_keys = new Set();
20+
let all_save_keys_list = [];
21+
1722
export async function set_opened_facts(data) {
1823
opened_facts = data;
1924
}
@@ -30,6 +35,20 @@ export async function set_entries_facts(data) {
3035
entries_facts = data;
3136
}
3237

38+
export async function set_all_save_keys(data) {
39+
console.assert(import.meta.env.DEV, "can be set only in dev mode");
40+
all_save_keys = new Set(data);
41+
all_save_keys_list = data;
42+
}
43+
44+
export function get_all_save_keys(data) {
45+
return [...all_save_keys_list];
46+
}
47+
48+
export function save_key_valid(key) {
49+
return all_save_keys.has(key);
50+
}
51+
3352
/** @param {Object<string, { entries: string[]; rumors: string[] }>} data */
3453
export async function set_joined_rumors(data) {
3554
joined_rumors = data;
@@ -38,14 +57,26 @@ export async function set_joined_rumors(data) {
3857
/**
3958
* @param {string} id
4059
* @param {boolean} show_unexplored
41-
* @returns {{ text: string }[]}
60+
* @returns {{ text: string; more_to_explore: boolean }[]}
4261
*/
4362
export function get_facts_for(id, show_unexplored) {
63+
return get_facts_ids_for(id, show_unexplored).map((fact) => ({
64+
text: tr[fact.id],
65+
more_to_explore: fact.more_to_explore || false,
66+
}));
67+
}
68+
69+
/**
70+
* @param {string} id
71+
* @param {boolean} show_unexplored
72+
* @returns {{ id: string; more_to_explore?: boolean }[]}
73+
*/
74+
export function get_facts_ids_for(id, show_unexplored) {
4475
let is_joined = id.includes(",");
4576

4677
if (id.match(RUMOR_REGEX)) {
4778
// clicked on rumor
48-
return [{ text: tr[id] }];
79+
return [{ id }];
4980
}
5081

5182
let facts;
@@ -68,12 +99,12 @@ export function get_facts_for(id, show_unexplored) {
6899
}
69100

70101
facts = facts.map((f) => {
71-
return { text: tr[f], more_to_explore: !opened_facts.has(f) };
102+
return { id: f, more_to_explore: !opened_facts.has(f) };
72103
});
73104

74105
if (has_more_to_explore(id) && !show_unexplored) {
75106
facts.push({
76-
text: tr[MORE_TO_EXPLORE_TR],
107+
id: MORE_TO_EXPLORE_TR,
77108
more_to_explore: true,
78109
});
79110
}

frontend/src/lib/draw.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
set_has_unexplored_cards,
1818
set_opened_cards_only_rumors,
1919
set_opened_facts,
20+
set_all_save_keys,
2021
} from "@/lib/data";
2122
import { detect_language } from "@/lib/language";
2223
import { coord_to_leaflet } from "@/lib/leaflet";
@@ -85,6 +86,9 @@ export async function generate_all_svg() {
8586
}
8687
set_opened_facts(opened_facts);
8788
OPENED_FACTS_COUNT.set(opened_facts.size);
89+
if (import.meta.env.DEV) {
90+
set_all_save_keys(save_keys);
91+
}
8892

8993
LOADING.update((n) => n + 1);
9094

0 commit comments

Comments
 (0)