TIC-80
TIC-80 copied to clipboard
load command behaves oddly around the website
The implementation of the website integration in TIC-80 creates the illusion of a folder structure; however, the load
command behaves oddly around this boundary.
Steps to reproduce
- Create a folder called
foo
. (The name is irrelevant.) -
cd foo
- Save a cart called
bar.tic
(Again, name is irrelevant and only used for instructions.) -
cd ..
-
load foo/bar.tic
- Observe how the file is loaded.
- Navigate into
tic80.com
and locate a cart. Remember the path of this cart. -
cd
back to the root directory - Attempt to
load
the cart using the path
Expected behavior The cart loads.
Actual behavior (as of 1.1.2837)
The load errors with file not found
or cart loading error
.
The issue seems to be in the handling of the website. Specifically, the website only gets considered as a loadable target if we're inside the website's folder (if tic_fs_ispubdir
returns true
, which only happens if our working directory is in the website). Otherwise, it tries to load from the local filesystem, which naturally fails.
Even if we're inside the website directory and attempt to load a file from a directory, it still doesn't work, this time because tic_fs_enum
only considers the working directory when trying to determine where a file exists (attempting to load, say, Play/Games/zracer.tic
from the base tic80.com
directory would only work if there was a file in the root path that had a filename
of Play/Games/zracer.tic
, which I was able to confirm via testing locally with my custom surf server).
The former issue could be solved by adding a check if we're in the root directory and loading a path which starts with TIC_HOST
, and the latter issue could be solved using dirname
and basename
(or equivalents) to split the path into directory (which is appended to the working directory) and filename to search for.