LÖVE 2D can interact with many things through the use of strings.
love.audio.getEffect("anEffect");
// Nothing crashes if anEffect didn't exist
love.filesystem.readFile("file.txt");
// No crash, just returns an error
This repo uses registries, optionally, to remove concerns about file paths, image files and other external things being written incorrectly or being misused.
interface FilePathRegistry {
"file.txt": any;
}
This registry will make sure "file.txt"
is the only file path that can be accessed.
TypeScript will make sure of this giving you compile-time errors and autocomplete options.
You can also use metadata on these entries.
interface FilePathRegistry {
"file.txt": { lines: 64 };
}
You (or a .sh
file) will have to make sure this metadata is true. But if you keep it up to date...
function read80LineFile(file: File<{
lines: 80
}>) {
// ...
}
const file = love.filesystem.read("file.txt");
read80LineFile(file);
// Not allowed, file must have 80 lines of text.
You can take this in depth as much as you want/can. Just note that simple comparisons like this are available, not too much else.