Skip to content

Commit

Permalink
feat: 0.2.9 Better header for scripts output
Browse files Browse the repository at this point in the history
Makes the array declaration at the top of output by sprites.py and
sheet_converter.py, have proper values for the supplied images.

At the moment sprites.py assumes equal-sized frames.
  • Loading branch information
jgabaut committed Aug 31, 2023
1 parent 9a4b816 commit fc7e54b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export SHELL=/bin/bash

VERSION= v0.2.8
VERSION= v0.2.9
FLAGS = -Werror -Wall -Wpedantic -Wfatal-errors

all: demo
Expand Down
4 changes: 2 additions & 2 deletions demofile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0.1.4
char sprites[31][18][18] = {
0.1.5
char chest_animation[31][18][18] = {

//Frame 1, file chest-animation/image1.png
{
Expand Down
2 changes: 1 addition & 1 deletion documentation/s4c.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "sprites4curses"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "0.2.8"
PROJECT_NUMBER = "0.2.9"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion s4c-animate/animate.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int load_sprites(char sprites[MAXFRAMES][MAXROWS][MAXCOLS], FILE* f, int rows, i
char line[1024];
char* file_version;
char* token;
char* READER_VERSION = "0.1.4";
char* READER_VERSION = "0.1.5";
int row = 0, frame = -1;

int check = -1;
Expand Down
4 changes: 2 additions & 2 deletions s4c-animate/animate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <ncurses.h>
#include <pthread.h>

#define S4C_ANIMATE_VERSION "0.2.8"
#define S4C_ANIMATE_VERSION "0.2.9"
#define S4C_ANIMATE_MAJOR_VERSION 0
#define S4C_ANIMATE_MINOR_VERSION 2
#define S4C_ANIMATE_PATCH_VERSION 8
#define S4C_ANIMATE_PATCH_VERSION 9

void s4c_printVersionToFile(FILE* f);
void s4c_echoVersionToFile(FILE* f);
Expand Down
5 changes: 3 additions & 2 deletions scripts/sheet_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import math

## The file format version.
FILE_VERSION = "0.1.4"
FILE_VERSION = "0.1.5"

# Functions
def usage():
Expand Down Expand Up @@ -76,6 +76,7 @@ def convert_spritesheet(filename, spriteSizeX, spriteSizeY, separatorSize, start
@param startX X coord of left corner of first sprite.
@param startY Y coord of left corner of first sprite.
"""
target_name = os.path.splitext(os.path.basename(filename))[0]

sprite_size = (spriteSizeX, spriteSizeY) # size of each sprite
separator_size = separatorSize # size of separator between sprites
Expand Down Expand Up @@ -134,7 +135,7 @@ def convert_spritesheet(filename, spriteSizeX, spriteSizeY, separatorSize, start
# Start file output, beginning with version number

print("{}".format(FILE_VERSION))
print("char sprites[{}][{}][{}] = ".format(len(sprites) +1, spriteSizeY+1, spriteSizeX+1) + "{\n")
print("char {}[{}][{}][{}] = ".format(target_name,len(sprites) +1, spriteSizeY+1, spriteSizeX+1) + "{\n")
for i, sprite in enumerate(sprites):
print("\t//Sprite {}, index {}".format(i + 1, i))
print("\t{")
Expand Down
30 changes: 18 additions & 12 deletions scripts/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import math

## The file format version.
FILE_VERSION = "0.1.4"
FILE_VERSION = "0.1.5"

# Expects the sprite directory name as first argument.
# File names format inside the directory should be "imageNUM.png".
Expand Down Expand Up @@ -124,30 +124,36 @@ def print_converted_sprites(direc):
"""
# We start the count from one so we account for one more cell for array declaration
frames = 1
target_name = os.path.basename(os.path.normpath(direc))

for file in sorted(glob.glob('{}/*.png'.format(direc)),
key=lambda f:
int(re.search(r'\d+', f).group())):
if frames == 1 :
ref_img = Image.open(file) #Open reference file to get output dimension. WIP
xsize = ref_img.size[0]+1
ysize = ref_img.size[1]+1
frames += 1

# Start file output, beginning with version number

print("{}".format(FILE_VERSION))
print("char sprites[{}][18][18] = ".format(frames) + "{\n")
print("char {}[{}][{}][{}] = ".format(target_name,frames,ysize,xsize) + "{\n")
idx = 1
for file in sorted(glob.glob('{}/*.png'.format(direc)),
key=lambda f:
int(re.search(r'\d+', f).group())):
# convert a sprite and print the result
sprite = convert_sprite(file)
print("\t//Frame {}".format(idx))
print("\t{")
for row in sprite:
print("\t\t\""+row+"\",")
print("\t},"+ "\n")
idx += 1
key=lambda f:
int(re.search(r'\d+', f).group())):
# convert a sprite and print the result
sprite = convert_sprite(file)
print("\t//Frame {}".format(idx))
print("\t{")
for row in sprite:
print("\t\t\""+row+"\",")
print("\t},"+ "\n")
idx += 1
print("};")


def main(argv):
"""! Main program entry."""
if len(argv) != 2:
Expand Down

0 comments on commit fc7e54b

Please sign in to comment.