-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented image assets archiving to
skap
(#31)
- Loading branch information
1 parent
f39bce8
commit 5d1e2a1
Showing
10 changed files
with
267 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ docs/www/node_modules/ | |
|
||
sparky | ||
sparky_debug | ||
assets.skap | ||
assets.skap.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <stdio.h> | ||
|
||
FILE *skap_file_create(void); | ||
|
||
void skap_file_destroy(FILE *fd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <raylib.h> | ||
#include <skap_defines.h> | ||
|
||
typedef struct { | ||
const char *name; | ||
u32 width; | ||
u32 height; | ||
u32 mipmaps; | ||
u8 format; | ||
} skap_idx_image_md; | ||
|
||
typedef struct { | ||
skap_idx_image_md metadata; | ||
usz blob_offset; | ||
usz blob_size; | ||
} skap_idx_image; | ||
|
||
skap_idx_image skap_idx_image_create(const char *name, Image *img); | ||
|
||
u8 skap_idx_image_append(FILE *fd, skap_idx_image *i); | ||
|
||
void skap_idx_image_link_blob(skap_idx_image *i, usz blob_offset, usz blob_size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include <errno.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <skap_file.h> | ||
#include <skap_defines.h> | ||
|
||
FILE *skap_file_create(void) { | ||
if (!access(SKAP_FILENAME, F_OK)) { | ||
printf(" RENAME " SKAP_FILENAME " -> " SKAP_FILENAME ".old\n"); | ||
if (rename(SKAP_FILENAME, SKAP_FILENAME ".old") == -1) { | ||
fprintf(stderr, "ERROR: rename(2) unable to rename the file (%s)\n", strerror(errno)); | ||
return 0; | ||
} | ||
} | ||
else printf(" TOUCH " SKAP_FILENAME "\n"); | ||
return fopen(SKAP_FILENAME, "ab"); | ||
} | ||
|
||
void skap_file_destroy(FILE *fd) { | ||
if (!fd) { | ||
printf("WARNING: skap_file_destroy :: `fd` is not a valid pointer, skipping destruction\n"); | ||
return; | ||
} | ||
fclose(fd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include <skap_idx_image.h> | ||
|
||
skap_idx_image skap_idx_image_create(const char *name, Image *img) { | ||
return (skap_idx_image) { | ||
.metadata = (skap_idx_image_md) { | ||
.name = name, | ||
.width = img->width, | ||
.height = img->height, | ||
.mipmaps = img->mipmaps, | ||
.format = img->format | ||
}, | ||
.blob_offset = 0, | ||
.blob_size = 0 | ||
}; | ||
} | ||
|
||
u8 skap_idx_image_append(FILE *fd, skap_idx_image *i) { | ||
if (!fd || !i) { | ||
fprintf(stderr, "ERROR: skap_idx_image_append :: `fd` and `i` need to be valid pointers\n"); | ||
return 0; | ||
} | ||
printf(" WRITE skap_idx_image(%s) >> " SKAP_FILENAME "\n", i->metadata.name); | ||
if (fwrite(i, sizeof(skap_idx_image), 1, fd) != 1) { | ||
fprintf(stderr, "ERROR: skap_idx_image_append :: unable to write to file\n"); | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
void skap_idx_image_link_blob(skap_idx_image *i, usz blob_offset, usz blob_size) { | ||
if (!i || !blob_offset || !blob_size) { | ||
printf("WARNING: skap_idx_image_link_blob :: args need to be valid, skipping linkage\n"); | ||
return; | ||
} | ||
printf(" LINK skap_idx_image(%s) -> {%zu, %zu}\n", i->metadata.name, blob_offset, blob_size); | ||
i->blob_offset = blob_offset; | ||
i->blob_size = blob_size; | ||
} |