The Hog GUI
- Download: gui-src.zip
The web-based GUI for Hog is a
Lustre app written in Gleam. The hog.zip you
downloaded for the project came with only the compiled result,
gui-files/gui.js. This example provides the Gleam source code.
Setup
You'll need your hog folder from the Hog project, along with Gleam and Node.js
(installed during the first Gleam lab).
Download. Click the gui-src.zip link at the top of this page, then unzip
it: on Mac or Linux, double-click the downloaded file; on Windows, right-click
it and choose Extract All.... (Safari on a Mac may unzip it for you.) You'll
get a folder named gui-src.
Move it into your hog folder. Move the gui-src folder into your hog
folder, so that it sits next to hog.py, hog_gui.py, and gui-files:
hog/
โโโ hog.py
โโโ hog_gui.py
โโโ gui-files/
โโโ gui-src/ โ the folder you just moved
โโโ gleam.toml
โโโ src/
โโโ dev/
Build the GUI. Open your hog folder in VS Code. From the Terminal
menu, select New Terminal, and type:
cd gui-src
gleam dev
This compiles the Gleam source and bundles it into one file,
gui-files/gui.js, replacing the GUI that came with the project. The first
time, Gleam downloads the packages that the GUI depends on, and npx downloads
esbuild, the tool that does the bundling, so you'll
need an internet connection.
Run it. Go back to your hog folder and start the GUI the same way as in
the project:
cd ..
python3 hog_gui.py
It serves the GUI you just built and runs the game using your hog.py.
After you change the source in gui-src/src, run gleam dev again from
gui-src and refresh the page. You don't need to restart python3 hog_gui.py
for a change to the GUI, only for a change to hog.py or hog_gui.py.
To go back to the original GUI, replace your gui-src folder with a fresh copy
from gui-src.zip and run gleam dev again. (The unchanged source builds the
same gui.js that came in hog.zip.)
What can go wrong?
- If
gleam devsays to put thegui-srcfolder inside yourhogfolder, check thatgui-srcsits next tohog_gui.py(not insidegui-filesor inside anothergui-srcfolder) and that you rancd gui-srcfirst. - If your code doesn't compile,
gleam devprints the error and leavesgui-files/gui.jsas it was. - If the terminal says that
gleam,node, ornpxis not found, repeat the Lab 8 setup, then quit and reopen VS Code.