Skip to content

Commit 1f580b5

Browse files
Separate DR Chapter 1 and Chapter 2 code viewers.
1 parent bfd2805 commit 1f580b5

File tree

11 files changed

+155
-22
lines changed

11 files changed

+155
-22
lines changed

.github/workflows/deploy-dr.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ jobs:
1717
run: |
1818
mkdir -p ~/.local/share/Steam/config
1919
echo "$STEAM_VDF" | base64 -d > ~/.local/share/Steam/config/config.vdf
20-
steamcmd +@ShutdownOnFailedCommand +@sSteamCmdForcePlatformType windows +force_install_dir $(pwd)/game +login $STEAM_USERNAME +app_update 1690940 validate +quit
20+
steamcmd +@ShutdownOnFailedCommand +@sSteamCmdForcePlatformType windows +force_install_dir $(pwd)/game +login $STEAM_USERNAME +app_update 1671210 validate +quit
2121
env:
2222
STEAM_VDF: ${{ secrets.STEAM_VDF }}
2323
STEAM_USERNAME: ${{ secrets.STEAM_USERNAME }}
2424
- name: Extract Deltarune's code
2525
run: |
26-
./utmtcli/UndertaleModCli load game/data.win --scripts 'scripts/ExportCodeFormatted.csx'
27-
mv game/Export_Code decompiled-deltarune
26+
./utmtcli/UndertaleModCli load game/chapter1_windows/data.win --scripts 'scripts/ExportCodeFormatted.csx'
27+
./utmtcli/UndertaleModCli load game/chapter2_windows/data.win --scripts 'scripts/ExportCodeFormatted.csx'
28+
mkdir decompiled-deltarune
29+
mv game/chapter1_windows/Export_Code decompiled-deltarune/ch1
30+
mv game/chapter2_windows/Export_Code decompiled-deltarune/ch2
2831
- name: Build
2932
run: ./build.sh deltarune
3033
- name: Publish
3134
uses: netlify/actions/cli@master
3235
with:
33-
args: deploy --dir=out --prod
36+
args: deploy --prod --dir=out --message="GitHub Actions"
3437
env:
3538
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID_DR }}
3639
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33
cd "${0%/*}"
44
rm -rf out
55
mkdir -p out
6-
cp -r "decompiled-$1" out/raw
6+
cp -rL "decompiled-$1" out/raw
77
find out/raw -name "*.gml" -exec sh -c 'cp "$1" "${1%.gml}.txt"' _ {} \;
88
cp -r static out
99
cp _headers out

data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Config:
1919
game: str
2020
links: Dict[str, str]
2121
cache: int
22+
chapters: Optional[List[str]] = None
2223

2324

2425
class Data:
@@ -30,6 +31,7 @@ def __init__(self, game: str):
3031
self.sums: Optional[Dict[str, str]] = None
3132
self.lang: Optional[Dict[str, str]] = None
3233
self.config: Optional[Config] = None
34+
self.chapter: int = -1
3335

3436
def load_json(self, filename: str) -> Any:
3537
script_dir = get_script_path()
@@ -119,6 +121,8 @@ def get_localized_string_ch1(self, key: str) -> str:
119121
def get_game_name(self) -> str:
120122
if self.config is None:
121123
self.config = self.load_config()
124+
if self.chapter >= 0:
125+
return f'{self.config.game} (Chapter {self.chapter + 1})'
122126
return self.config.game
123127

124128
def get_game_links(self) -> Dict[str, str]:
@@ -130,3 +134,11 @@ def get_cache_version(self) -> int:
130134
if self.config is None:
131135
self.config = self.load_config()
132136
return self.config.cache
137+
138+
def get_chapters(self) -> Optional[List[str]]:
139+
if self.config is None:
140+
self.config = self.load_config()
141+
return self.config.chapters
142+
143+
def select_chapter(self, chapter_idx: int):
144+
self.chapter = chapter_idx

data/deltarune/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"game": "Deltarune",
3+
"chapters": ["ch1", "ch2"],
34
"links": {
45
"Source code": "https://github.com/utdrwiki/code-viewer",
56
"r/Underminers": "https://www.reddit.com/r/Underminers/",
67
"TCRF": "https://tcrf.net/Deltarune",
78
"Wiki": "https://deltarune.wiki/"
89
},
9-
"cache": 2
10+
"cache": 1
1011
}

generate.py

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,72 @@
11
#!/usr/bin/env python
22
import argparse
3+
import hashlib
34
import os
5+
from pathlib import Path
6+
from typing import Dict, List, Set
47

58
from jinja2 import Environment, FileSystemLoader, select_autoescape
69

710
from data import Data
8-
from index import process_scripts, write_index
11+
from index import ScriptIndex, process_scripts, write_index
912
from script import render_script, write_script
1013
from util import get_script_path
1114

15+
AggregateIndex = Dict[str, List[int]]
16+
17+
18+
env = Environment(
19+
loader=FileSystemLoader('templates'),
20+
autoescape=select_autoescape(['html'])
21+
)
22+
23+
24+
def process_indices(indices: List[ScriptIndex], data: Data) -> AggregateIndex:
25+
aggregate: AggregateIndex = {}
26+
checksums: Dict[str, Set[str]] = {}
27+
for chapter_idx, index in enumerate(indices):
28+
for script, text in index.text.items():
29+
if script not in aggregate:
30+
aggregate[script] = []
31+
checksums[script] = set()
32+
fulltext_bytes = '\n'.join(text).encode('utf-8')
33+
checksum = hashlib.md5(fulltext_bytes).hexdigest()
34+
if checksum not in checksums[script]:
35+
checksums[script].add(checksum)
36+
aggregate[script].append(chapter_idx)
37+
return aggregate
38+
39+
40+
def write_redirects(aggregate: AggregateIndex, data: Data, output_dir: Path):
41+
redirects: Dict[str, str] = {}
42+
chapters = data.get_chapters() or []
43+
for script, chapter_indices in aggregate.items():
44+
if len(chapter_indices) > 1:
45+
with open(output_dir / f'{script}.html', 'w') as disambig_file:
46+
disambig_file.write(env.get_template('disambig.html').render(
47+
script_name=script,
48+
chapters=[chapters[idx] for idx in chapter_indices],
49+
game=data.get_game_name(),
50+
links=data.get_game_links(),
51+
))
52+
else:
53+
chapter = chapters[chapter_indices[0]]
54+
redirects[f'/{script}.html'] = f'/{chapter}/{script}.html'
55+
with open(output_dir / '_redirects', 'w') as redirects_file:
56+
for old_path, new_path in redirects.items():
57+
redirects_file.write(f'{old_path} {new_path}\n')
58+
59+
60+
def write_chapter_index(data: Data, output_dir: Path):
61+
chapters = data.get_chapters() or []
62+
with open(output_dir / 'index.html', 'w') as index_file:
63+
index_file.write(env.get_template('chapters.html').render(
64+
chapters=chapters,
65+
game=data.get_game_name(),
66+
links=data.get_game_links(),
67+
))
68+
69+
1270
if __name__ == '__main__':
1371
parser = argparse.ArgumentParser(
1472
description='Generates the code viewer website.'
@@ -20,16 +78,30 @@
2078
)
2179
args = parser.parse_args()
2280
data = Data(args.game)
81+
chapters = data.get_chapters()
2382
script_dir = get_script_path()
2483
decompiled_dir = script_dir / f'decompiled-{args.game}'
2584
output_dir = script_dir / 'out'
2685
os.makedirs(output_dir, exist_ok=True)
27-
env = Environment(
28-
loader=FileSystemLoader('templates'),
29-
autoescape=select_autoescape(['html'])
30-
)
31-
index = process_scripts(data, decompiled_dir)
32-
write_index(index, data, output_dir)
33-
for script in index.text.keys():
34-
rendered = render_script(script, index.text, data)
35-
write_script(rendered, script, output_dir)
86+
if chapters is not None:
87+
indices = []
88+
for chapter_idx, chapter in enumerate(chapters):
89+
decompiled_dir_ch = decompiled_dir / chapter
90+
output_dir_ch = output_dir / chapter
91+
os.makedirs(output_dir_ch, exist_ok=True)
92+
data.select_chapter(chapter_idx)
93+
index = process_scripts(data, decompiled_dir_ch)
94+
write_index(index, data, output_dir_ch)
95+
for script in index.text.keys():
96+
rendered = render_script(script, index.text, data)
97+
write_script(rendered, script, output_dir_ch)
98+
data.select_chapter(-1)
99+
indices.append(index)
100+
write_redirects(process_indices(indices, data), data, output_dir)
101+
write_chapter_index(data, output_dir)
102+
else:
103+
index = process_scripts(data, decompiled_dir)
104+
write_index(index, data, output_dir)
105+
for script in index.text.keys():
106+
rendered = render_script(script, index.text, data)
107+
write_script(rendered, script, output_dir)

index.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,14 @@ def process_scripts(data: Data, decompiled_dir: Path) -> ScriptIndex:
8484
section, segment = classify(filename, data)
8585
if segment not in index.sections[section].entries:
8686
index.sections[section].entries[segment] = []
87+
chapters = data.get_chapters()
88+
if chapters is None:
89+
chapter_segment = ''
90+
else:
91+
chapter_segment = f'/{chapters[data.chapter]}'
8792
index.sections[section].entries[segment].append(Entry(
8893
url=file.replace('.gml', '.html'),
89-
raw_url=f"raw/{file.replace('.gml', '.txt')}",
94+
raw_url=f"/raw{chapter_segment}/{file.replace('.gml', '.txt')}",
9095
name=name,
9196
lines=len(lines)
9297
))

templates/chapters.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{ game }} script viewer</title>
5+
{% include 'partials/head.html' %}
6+
<link rel="stylesheet" href="/static/index.css" />
7+
</head>
8+
<body>
9+
<h1>{{ game }} script viewer</h1>
10+
11+
{% include 'partials/info.html' %}
12+
13+
<ul>
14+
{% for chapter in chapters %}
15+
<li><a href="/{{ chapter }}/">Chapter {{ loop.index }}</a></li>
16+
{% endfor %}
17+
</ul>
18+
19+
</body>
20+
</html>

templates/disambig.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>{{ game }} script viewer</title>
5+
{% include 'partials/head.html' %}
6+
<link rel="stylesheet" href="/static/index.css" />
7+
</head>
8+
<body>
9+
<h1>{{ game }} script viewer</h1>
10+
11+
<h2>{{ script_name }}</h2>
12+
<p>This script exists in multiple chapters:</p>
13+
<ul>
14+
{% for chapter in chapters %}
15+
<li><a href="{{ chapter }}/{{ script_name }}.html">Chapter {{ loop.index }}</a></li>
16+
{% endfor %}
17+
</ul>
18+
19+
</body>
20+
</html>

templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<head>
44
<title>{{ game }} script viewer</title>
55
{% include 'partials/head.html' %}
6-
<link rel="stylesheet" href="static/index.css" />
7-
<script src="static/search.js"></script>
6+
<link rel="stylesheet" href="/static/index.css" />
7+
<script src="/static/search.js"></script>
88
</head>
99
<body>
1010
<h1>{{ game }} script viewer</h1>

templates/partials/head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<link rel="stylesheet" href="static/main.css" />
1+
<link rel="stylesheet" href="/static/main.css" />
22
<meta charset="utf-8">
33
<meta name="viewport" content="width=device-width, initial-scale=1">
44
<meta name="robots" content="noindex">

0 commit comments

Comments
 (0)