Fixed bug in setup script and added sprite for examples.

This commit is contained in:
Kapendev 2024-06-09 20:29:02 +03:00
parent ca5c140e3c
commit a21abd929a
5 changed files with 45 additions and 23 deletions

View file

@ -55,16 +55,17 @@ dub run popka:setup
The last line will download raylib and create some folders necessary for Popka to function properly. The folders:
* `assets`: This folder is used to store game assets such as images, sounds and fonts.
* `web`: This folder is used for exporting to the web.
* assets: This folder is used to store game assets such as images, sounds and fonts.
* web: This folder is used for exporting to the web.
The last line also changes the default app.d file.
Once the installation is complete, you should be able to compile by running:
Once the installation is complete, you should be able to compile/run with:
```bash
dub run
```
You can pass `offline` to the script if you don't want to download raylib.
For more info about exporting to web, see [this](#web-support).
## Documentation

View file

@ -9,11 +9,11 @@
"configurations": [
{
"name": "pdefault",
"excludedSourceFiles": ["examples/*.d", "web/source/*.d"]
"excludedSourceFiles": ["examples/*.d", "setup/source/*.d", "web/source/*.d"]
},
{
"name": "ptest",
"excludedSourceFiles": ["examples/*.d", "web/source/*.d", "source/popka/package.d", "source/popka/game/*.d", "source/popka/vendor/*.d"]
"excludedSourceFiles": ["examples/*.d", "setup/source/*.d", "web/source/*.d", "source/popka/package.d", "source/popka/game/*.d", "source/popka/vendor/*.d"]
}
],
"subPackages" : [

View file

@ -1,5 +1,8 @@
# Examples
> [!NOTE]
> For examples that use sprites, you must download the [atlas.png](atlas.png) file and save it in your project's assets folder.
## [Hello](hello.d)
This example serves as a classic hello-world program, introducing the fundamental structure of a Popka program.

BIN
examples/atlas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

@ -9,6 +9,21 @@ import std.stdio;
import std.file;
import std.process;
// The config.
// ----------
enum noLibsArg = "offline";
enum dubFile = buildPath(".", "dub.json");
enum dubyFile = buildPath(".", "dub.selections.json");
enum appFile = buildPath(".", "source", "app.d");
enum gitignoreFile = buildPath(".", ".gitignore");
enum assetsDir = buildPath(".", "assets");
enum webDir = buildPath(".", "web");
// ----------
enum defaultDubContent = `{
"name" : "game",
"description" : "A game made with Popka.",
@ -39,7 +54,7 @@ enum defaultDubContent = `{
"targetType": "executable",
"platforms": ["windows"],
"libs": [
"raylibdll"
"raylib"
]
},
{
@ -112,33 +127,36 @@ void deleteFile(const(char)[] path) {
}
}
int main() {
if (check(buildPath(".", "dub.json"), false)) {
int main(string[] args) {
if (check(dubFile, false)) {
writeln("Error: This is not a DUB project.");
return 1;
}
writeln("Info: Pass `%s` if you don't want to download raylib.".format(noLibsArg));
// Use the raylib-d script to download the raylib library files.
// We also have to use `spawnShell` here because raylib-d:install does not accept arguments.
// TODO: Ask the raylib-d project to do something about that.
run("dub add raylib-d");
writeln();
writeln(`"Saying yes to happiness means learning to say no to the things and people that stress you out." - Thema Davis`);
writeln();
auto pid = spawnShell("dub run raylib-d:install");
wait(pid);
if (args.length == 1 || (args.length > 1 && args[1] != noLibsArg)) {
run("dub add raylib-d");
writeln();
writeln(`"Saying yes to happiness means learning to say no to the things and people that stress you out." - Thema Davis`);
writeln();
auto pid = spawnShell("dub run raylib-d:install");
wait(pid);
}
// Delete the old files.
deleteFile(buildPath(".", "dub.json"));
deleteFile(buildPath(".", "dub.selections.json"));
deleteFile(buildPath(".", ".gitignore"));
deleteFile(buildPath(".", "source", "app.d"));
deleteFile(dubFile);
deleteFile(dubyFile);
deleteFile(gitignoreFile);
deleteFile(appFile);
// Create the new files.
std.file.write(buildPath(".", "dub.json"), defaultDubContent);
std.file.write(buildPath(".", ".gitignore"), defaultGitignoreContent);
std.file.write(buildPath(".", "source", "app.d"), defaultAppContent);
if (check(buildPath(".", "assets"), false)) std.file.mkdir(buildPath(".", "assets"));
if (check(buildPath(".", "web"), false)) std.file.mkdir(buildPath(".", "web"));
std.file.write(dubFile, defaultDubContent);
std.file.write(gitignoreFile, defaultGitignoreContent);
std.file.write(appFile, defaultAppContent);
if (check(assetsDir, false)) std.file.mkdir(assetsDir);
if (check(webDir, false)) std.file.mkdir(webDir);
return 0;
}