From 14f6cbebf7ad394f1b104b99c3ef788ce1eebddc Mon Sep 17 00:00:00 2001
From: rodri <rgl@antares-labs.eu>
Date: Thu, 7 Nov 2024 15:39:43 +0000
Subject: copy the assets into /sys/games/lib.

---
 bts.c  | 26 ++++++++++++++++----------
 mkfile |  7 +++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/bts.c b/bts.c
index 8cc9712..5e8f08f 100644
--- a/bts.c
+++ b/bts.c
@@ -129,7 +129,9 @@ Cursor aimcursor = {
 	}
 };
 char deffont[] = "/lib/font/bit/pelm/unicode.9.font";
-char titlefontpath[] = "assets/font/gunmetal/gunmetal.48.font";
+char assetdir[] = "/sys/games/lib/battleship";
+//char assetdir[] = "assets";
+char titlefontpath[] = "font/gunmetal/gunmetal.48.font";
 Font *titlefont;
 char winspec[32];
 char uid[8+1], oid[8+1];
@@ -557,21 +559,23 @@ initsfx(void)
 		double gain;
 		int loops;
 	} sndtab[NSOUNDS] = {
-	 [SBG0]		{"assets/sfx/bg0.mp3", 1.0, 1},
-	 [SBG1]		{"assets/sfx/bg1.mp3", 1.0, 1},
-	 [SBG2]		{"assets/sfx/bg2.mp3", 1.0, 1},
-	 [SCANNON]	{"assets/sfx/cannon.mp3", 5.0, 0},
-	 [SWATER]	{"assets/sfx/water.mp3", 3.0, 0},
-	 [SVICTORY]	{"assets/sfx/victory.mp3", 1.0, 1},
-	 [SDEFEAT]	{"assets/sfx/defeat.mp3", 1.0, 1},
+	 [SBG0]		{"sfx/bg0.mp3", 1.0, 1},
+	 [SBG1]		{"sfx/bg1.mp3", 1.0, 1},
+	 [SBG2]		{"sfx/bg2.mp3", 1.0, 1},
+	 [SCANNON]	{"sfx/cannon.mp3", 5.0, 0},
+	 [SWATER]	{"sfx/water.mp3", 3.0, 0},
+	 [SVICTORY]	{"sfx/victory.mp3", 1.0, 1},
+	 [SDEFEAT]	{"sfx/defeat.mp3", 1.0, 1},
 	};
 	int i;
+	char aux[64];
 
 	initaudio(44100);
 	audio_set_master_gain(0.5);
 
 	for(i = 0; i < NSOUNDS; i++){
-		playlist[i] = loadaudiosource(sndtab[i].path);
+		snprint(aux, sizeof aux, "%s/%s", assetdir, sndtab[i].path);
+		playlist[i] = loadaudiosource(aux);
 		if(playlist[i] == nil)
 			sysfatal("loadaudiosource: %r");
 		audio_set_gain(playlist[i], sndtab[i].gain);
@@ -1066,6 +1070,7 @@ usage(void)
 void
 threadmain(int argc, char *argv[])
 {
+	char aux[64];
 	char *addr;
 	char *user;
 	int fd;
@@ -1113,7 +1118,8 @@ threadmain(int argc, char *argv[])
 	worldrf.bx = Vec2(1,0);
 	worldrf.by = Vec2(0,1);
 
-	titlefont = openfont(display, titlefontpath);
+	snprint(aux, sizeof aux, "%s/%s", assetdir, titlefontpath);
+	titlefont = openfont(display, aux);
 	if(titlefont == nil)
 		sysfatal("openfont: %r");
 
diff --git a/mkfile b/mkfile
index 689948b..68b0873 100644
--- a/mkfile
+++ b/mkfile
@@ -19,14 +19,21 @@ HFILES=\
 	fns.h\
 	mixer.h\
 
+ASSETDIR=/sys/games/lib/battleship
+
 </sys/src/cmd/mkmany
 
 ohman:V:
 	cp bts.man $MAN/battleship
 
 install:V: ohman
+	for(i in $TARG)
+		mk $MKFLAGS $i.install
+	mkdir -p $ASSETDIR
+	dircp assets $ASSETDIR
 
 uninstall:V:
 	for(i in $TARG)
 		rm -f $BIN/$i
 	rm -f $MAN/battleship
+	rm -rf $ASSETDIR
-- 
cgit v1.2.3