Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/deploy-dr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ jobs:
./utmtcli/UndertaleModCli load game/chapter3_windows/data.win --scripts 'scripts/ExportCodeFormatted.csx'
./utmtcli/UndertaleModCli load game/chapter4_windows/data.win --scripts 'scripts/ExportCodeFormatted.csx'
mkdir decompiled-deltarune
mv game/Export_Code decompiled-deltarune/init
mv game/chapter1_windows/Export_Code decompiled-deltarune/ch1
mv game/chapter2_windows/Export_Code decompiled-deltarune/ch2
mv game/chapter3_windows/Export_Code decompiled-deltarune/ch3
mv game/chapter4_windows/Export_Code decompiled-deltarune/ch4
- name: Build
run: ./build.sh deltarune
run: python3 build.py deltarune
- name: Publish
uses: netlify/actions/cli@master
with:
args: deploy --prod --dir=out --message="GitHub Actions" --timeout=3600
args: deploy --prod --dir=out/deltarune --message="GitHub Actions" --timeout=3600
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID_DR }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
./utmtcli/UndertaleModCli load game/assets/game.unx --scripts 'scripts/ExportCodeFormatted.csx'
mv game/assets/Export_Code decompiled-undertale
- name: Build
run: ./build.sh undertale
run: python3 build.py undertale
- name: Publish
uses: netlify/actions/cli@master
with:
args: deploy --dir=out --prod
args: deploy --dir=out/undertale --prod
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID_UT }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/deploy-uty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
./utmtcli/UndertaleModCli load data.win --scripts 'scripts/ExportCodeFormatted.csx'
mv Export_Code decompiled-undertaleyellow
- name: Build
run: ./build.sh undertaleyellow
run: python3 build.py undertaleyellow
- name: Publish
uses: netlify/actions/cli@master
with:
args: deploy --dir=out --prod
args: deploy --dir=out/undertaleyellow --prod
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID_UTY }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ While this may not be suited for personal use, contributions that make it easier

## Building

Download either Undertale, Deltarune, or Undertale Yellow and extract their scripts using [UndertaleModTool](https://github.com/UnderminersTeam/UndertaleModTool)'s `ExportAllCode.csx` script. The scripts need to be located in `decompiled-{undertale,deltarune,undertaleyellow}` directories.
Download either Undertale, Deltarune, or Undertale Yellow and extract their scripts using [UndertaleModTool](https://github.com/UnderminersTeam/UndertaleModTool)'s `ExportAllCode.csx` script. The scripts need to be located in `decompiled-{undertale,deltarune,undertaleyellow}` directories. For multi-chapter games (deltarune), use subdirectories for individual chapters' scripts (e.g. `decompiled-deltarune/{ch1,ch2,ch3,ch4,init}`).

After installing prerequisites, first install required dependencies of the project using `pip install -r requirements.txt`, then build the site using `./build.sh [game]`. The site is placed by default in the `out` directory. To view the site after building, (if you have Python installed), run `./dev.sh`. A Bash (or any Linux shell) environment is assumed when running the mentioned commands.
After installing prerequisites, first install required dependencies of the project using `pip install -r requirements.txt`, then build the site using `python3 build.py [game]`. The site is placed by default in the `out/[game]` directory. To view the site after building, (if you have Python installed), run `./dev.sh [game]`. A Bash (or any Linux shell) environment is assumed when running the mentioned commands.

## Disclaimer

Expand Down
158 changes: 158 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import argparse
import os
import zipfile
from io import BytesIO
from os.path import dirname, exists, join, relpath
from shutil import copyfile, rmtree
from typing import Optional

import requests
from loguru import logger
from tqdm import tqdm

from data import Data
from generate import generate

DIR = dirname(__file__)
STATIC = join(DIR, 'static')


def download(url: str, file: str):
data = requests.get(url).content
parent = dirname(file)

if not exists(parent):
os.makedirs(parent)

with open(file, 'wb') as f:
f.write(data)


def build(game: str, chapter: Optional[str]):
out = join(DIR, 'out', game)

raw = (
join(out, 'raw', chapter) if chapter is not None else join(out, 'raw')
)

input_dir = (
join(DIR, f'decompiled-{game}', chapter)
if chapter is not None
else join(DIR, f'decompiled-{game}')
)

logger.info(f'Building chapter: {chapter}')
logger.info('Finding script files...')

scripts: list[str] = []

for root, _, files in os.walk(input_dir):
for name in files:
if name.lower().endswith('.gml'):
scripts.append(join(root, name))

logger.info('Copying script files...')

for file in tqdm(scripts):
rel = relpath(file, input_dir)
target = join(raw, rel)
txt = join(raw, '.'.join(rel.split('.')[:-1]) + '.txt')
parent = dirname(target)

if not exists(parent):
os.makedirs(parent)

copyfile(file, target)
copyfile(file, txt)


def run(game: str):
data = Data(game)
out = join(DIR, 'out', game)
static_out = join(out, 'static')

if exists(out):
logger.info('Clearing existing output...')
rmtree(out)

os.makedirs(out)

chapters = data.get_chapters()

if chapters is not None and len(chapters) > 0:
logger.info('Building chapters...')

for chapter in chapters.keys():
build(game, chapter)
else:
build(game, None)

logger.info('Copying static files...')

static_files: list[str] = []

for root, _, files in os.walk(STATIC):
for file in files:
static_files.append(relpath(join(root, file), STATIC))

os.makedirs(static_out)

for file in tqdm(static_files):
out_path = join(static_out, file)
parent = dirname(out_path)

if not exists(parent):
os.makedirs(parent)

copyfile(join(STATIC, file), out_path)

copyfile(join(DIR, '_headers'), join(out, '_headers'))

logger.info('Downloading font...')

font_url = (
'https://download-cdn.jetbrains.com/fonts/JetBrainsMono-2.304.zip'
)
data = requests.get(font_url).content

with zipfile.ZipFile(BytesIO(data), 'r') as z:
z.extractall(static_out)

logger.info('Downloading highlight.js...')

hjs_base = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1'

download(
f'{hjs_base}/highlight.min.js',
join(static_out, 'highlight', 'highlight.min.js'),
)

download(
f'{hjs_base}/languages/gml.min.js',
join(static_out, 'highlight', 'gml.min.js'),
)

download(
f'{hjs_base}/styles/github-dark.min.css',
join(static_out, 'highlight', 'github-dark.min.css'),
)

logger.info('Generating website...')

generate(game)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Generates the code viewer website.'
)

parser.add_argument(
'game',
type=str,
help='game for which to generate the website',
)

args = parser.parse_args()

run(args.game)
10 changes: 0 additions & 10 deletions build.sh

This file was deleted.

27 changes: 18 additions & 9 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Config:
game: str
links: Dict[str, str]
cache: int
chapters: Optional[List[str]] = None
chapters: Optional[Dict[str, str]] = None
footer: Optional[str] = None


Expand All @@ -32,7 +32,8 @@ def __init__(self, game: str):
self.sums: Optional[Dict[str, str]] = None
self.lang: Optional[Dict[str, str]] = None
self.config: Optional[Config] = None
self.chapter: int = -1
self.chapter: Optional[str] = None
self.chapter_id: Optional[str] = None

def load_json(self, filename: str) -> Any:
script_dir = get_script_path()
Expand All @@ -42,7 +43,9 @@ def load_json(self, filename: str) -> Any:

def load_textdata(self, scriptname: str) -> Dict[str, str]:
script_dir = get_script_path()
lang_file = script_dir / 'out' / 'raw' / f'{scriptname}.gml'
lang_file = (
script_dir / 'out' / self.game / 'raw' / f'{scriptname}.gml'
)
ret = {}
textdata_regex = re.compile(
r'ds_map_add\(global\.text_data_[a-z]+, '
Expand Down Expand Up @@ -100,7 +103,10 @@ def get_room_by_name(self, room_name: str) -> Optional[Room]:
if self.rooms is None:
self.rooms = self.load_rooms()
for room in self.rooms:
if room.name == room_name:
if room.name == room_name or (
self.chapter is not None
and room.name == f'{room_name}_{self.chapter_id}'
):
return room
return None

Expand All @@ -122,8 +128,8 @@ def get_localized_string_ch1(self, key: str) -> str:
def get_game_name(self) -> str:
if self.config is None:
self.config = self.load_config()
if self.chapter >= 0:
return f'{self.config.game} (Chapter {self.chapter + 1})'
if self.chapter_id is not None and self.chapter_id != '':
return f'{self.config.game} ({self.chapter})'
return self.config.game

def get_game_links(self) -> Dict[str, str]:
Expand All @@ -141,10 +147,13 @@ def get_cache_version(self) -> int:
self.config = self.load_config()
return self.config.cache

def get_chapters(self) -> Optional[List[str]]:
def get_chapters(self) -> Optional[Dict[str, str]]:
if self.config is None:
self.config = self.load_config()
return self.config.chapters

def select_chapter(self, chapter_idx: int):
self.chapter = chapter_idx
def select_chapter(
self, chapter_id: Optional[str], chapter: Optional[str]
):
self.chapter_id = chapter_id
self.chapter = chapter
8 changes: 7 additions & 1 deletion data/deltarune/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"game": "Deltarune",
"chapters": ["ch1", "ch2", "ch3", "ch4"],
"chapters": {
"init": "Chapter Select",
"ch1": "Chapter 1",
"ch2": "Chapter 2",
"ch3": "Chapter 3",
"ch4": "Chapter 4"
},
"links": {
"Source code": "https://github.com/utdrwiki/code-viewer",
"r/Underminers": "https://www.reddit.com/r/Underminers/",
Expand Down
2 changes: 1 addition & 1 deletion dev.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
cd "${0%/*}"
python -m http.server -d out
python -m http.server -d out/"$1"
Loading