Skip to content

Commit a5bf21c

Browse files
committed
fix: use wrapped s4c.h inclusion in palette
1 parent 9865dde commit a5bf21c

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

s4c/core/palette.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
import sys
3535
import os
3636
from .utils import convert_mode_lit
37+
from .utils import print_wrapped_s4c_inclusion
3738

3839
## The file format version.
39-
FILE_VERSION = "0.2.2"
40-
SCRIPT_VERSION = "0.1.2"
40+
FILE_VERSION = "0.2.3"
41+
SCRIPT_VERSION = "0.1.3"
4142
F_STRING_ARGS = "[--cfile-no-include] <mode> <palette> <s4c path>"
4243

4344
# Expects the palette name as first argument, output directory as second argument.
@@ -108,8 +109,8 @@ def convert_palette(mode, palette_path, s4c_path, *args):
108109

109110
if mode == "header":
110111
print(f"#ifndef {target_name.upper()}_S4C_H_")
111-
print(f"#define {target_name.upper()}_S4C_H_")
112-
print(f"#include \"{s4c_path}/sprites4curses/src/s4c.h\"\n")
112+
print(f"#define {target_name.upper()}_S4C_H_\n")
113+
print_wrapped_s4c_inclusion(s4c_path)
113114
print(f"#define {target_name.upper()}_S4C_H_VERSION \"{FILE_VERSION}\"")
114115
print(f"#define {target_name.upper()}_S4C_H_TOTCOLORS {read_colors}")
115116
print("\n/**")

s4c/core/utils.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def convert_mode_lit(mode):
6060
return "INVALID"
6161

6262
def print_animation_header(target_name, file_version):
63-
"""! Print the beginning of s4c header for a target."""
63+
"""! Print the beginning of animation header for a target."""
6464
print(f"#ifndef {target_name.upper()}_S4C_H_")
6565
print(f"#define {target_name.upper()}_S4C_H_")
6666
print(f"#define {target_name.upper()}_S4C_H_VERSION \"{file_version}\"")
@@ -69,8 +69,20 @@ def print_animation_header(target_name, file_version):
6969
print(f" * Declares animation matrix vector for {target_name}.")
7070
print(" */")
7171

72+
def print_wrapped_s4c_inclusion(s4c_path):
73+
"""! Print the wrapped s4c.h inclusion."""
74+
print("#ifndef S4C_HAS_ANIMATE")
75+
print("#define S4C_SCRIPTS_PALETTE_ANIMATE_CLEANUP")
76+
print("#define S4C_HAS_ANIMATE")
77+
print("#endif //!S4C_HAS_ANIMATE")
78+
print(f"#include \"{s4c_path}/sprites4curses/src/s4c.h\"")
79+
print("#ifdef PALETTE_ANIMATE_CLEANUP")
80+
print("#undef S4C_HAS_ANIMATE")
81+
print("#undef S4C_SCRIPTS_PALETTE_ANIMATE_CLEANUP")
82+
print("#endif //PALETTE_ANIMATE_CLEANUP\n")
83+
7284
def print_heading(mode, target_name, file_version, num_frames, s4c_path):
73-
"""! Print the actual s4c header for a target."""
85+
"""! Print the actual header for a target."""
7486
if mode == "s4c":
7587
print(f"{file_version}")
7688
elif mode == "header":
@@ -82,8 +94,8 @@ def print_heading(mode, target_name, file_version, num_frames, s4c_path):
8294
elif mode == "header-exp":
8395
print_animation_header(target_name, file_version)
8496
#s4c_path = args[0]
97+
print_wrapped_s4c_inclusion(s4c_path)
8598
print(f"extern S4C_Sprite {target_name}[{num_frames}];\n")
86-
print(f"#include \"{s4c_path}/sprites4curses/src/s4c.h\"\n")
8799
print(f"\n#endif // {target_name.upper()}_S4C_H_")
88100
return True
89101
elif mode in ('cfile', 'cfile-exp'):

s4c/s4c_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from .core.sheet_converter import main as sheet_converter_main
4343
from .core.png_resize import main as png_resize_main
4444

45-
S4C_CLI_VERSION = "0.1.3"
45+
S4C_CLI_VERSION = "0.1.4"
4646

4747
EXPECTED_S4C_ANIMATE_V = "0.4.8"
4848

0 commit comments

Comments
 (0)