Skip to content

Commit

Permalink
chore: avoid match for python <3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabaut committed Jan 31, 2025
1 parent 24729b5 commit 96d4343
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
22 changes: 3 additions & 19 deletions s4c/core/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import os
from PIL import Image
from .utils import convert_mode_lit
from .utils import print_animation_header
from .utils import print_heading
from .utils import get_converted_char
from .utils import new_char_map
from .utils import log_wrong_argnum
Expand Down Expand Up @@ -145,24 +145,8 @@ def print_converted_sprites(mode, direc, *args):

# Start file output, beginning with version number

match mode:
case "s4c":
print(f"{FILE_VERSION}")
case "header":
print_animation_header(target_name, FILE_VERSION)
#print("extern char {}[{}][{}][{}];".format(target_name,frames,ysize,xsize))
print(f"extern char {target_name}[{frames}][MAXROWS][MAXCOLS];")
print(f"\n#endif // {target_name.upper()}_S4C_H_")
return
case "header-exp":
print_animation_header(target_name, FILE_VERSION)
#s4c_path = args[0]
print(f"extern S4C_Sprite {target_name}[{frames}];\n")
print(f"#include \"{args[0]}/sprites4curses/src/s4c.h\"\n")
print(f"\n#endif // {target_name.upper()}_S4C_H_")
return
case ('cfile', 'cfile-exp'):
print(f"#include \"{target_name}.h\"\n")
if print_heading(mode, target_name, FILE_VERSION, frames, args[0]):
return

if mode == "cfile":
#print("char {}[{}][{}][{}] = ".format(target_name,frames,ysize,xsize) + "{\n")
Expand Down
23 changes: 22 additions & 1 deletion s4c/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def convert_mode_lit(mode):
return "INVALID"

def print_animation_header(target_name, file_version):
"""! Print the s4c hader for a target."""
"""! Print the beginning of s4c header for a target."""
print(f"#ifndef {target_name.upper()}_S4C_H_")
print(f"#define {target_name.upper()}_S4C_H_")
print(f"#define {target_name.upper()}_S4C_H_VERSION \"{file_version}\"")
Expand All @@ -69,6 +69,27 @@ def print_animation_header(target_name, file_version):
print(f" * Declares animation matrix vector for {target_name}.")
print(" */")

def print_heading(mode, target_name, file_version, num_frames, s4c_path):
"""! Print the actual s4c header for a target."""
if mode == "s4c":
print(f"{file_version}")
elif mode == "header":
print_animation_header(target_name, file_version)
#print("extern char {}[{}][{}][{}];".format(target_name,frames,ysize,xsize))
print(f"extern char {target_name}[{num_frames}][MAXROWS][MAXCOLS];")
print(f"\n#endif // {target_name.upper()}_S4C_H_")
return True
elif mode == "header-exp":
print_animation_header(target_name, file_version)
#s4c_path = args[0]
print(f"extern S4C_Sprite {target_name}[{num_frames}];\n")
print(f"#include \"{s4c_path}/sprites4curses/src/s4c.h\"\n")
print(f"\n#endif // {target_name.upper()}_S4C_H_")
return True
elif mode in ('cfile', 'cfile-exp'):
print(f"#include \"{target_name}.h\"\n")
return False

def get_converted_char(char_map, r, g, b):
""""! Returns a char looking up char_map, for passed color."""
if (r, g, b) in char_map:
Expand Down

0 comments on commit 96d4343

Please sign in to comment.