feat: add empty tile if missing
This commit is contained in:
@@ -87,6 +87,7 @@ uv-run-sample-%: .venv ## uv run (project) sample/(xxx)
|
||||
--sentences-input sample/$*_sentences.txt \
|
||||
--functions \
|
||||
--includes \
|
||||
--add-empty \
|
||||
|
||||
.PHONY: ruff
|
||||
ruff: .venv ## ruff check
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
```txt
|
||||
usage: glsl-glyphs [-h] [-i INPUT_FILE] [-n NAME] [-o OUTPUT_FILE] [-g NAMES_FILE] [-s SETS_FILE] [-f | --functions | --no-functions]
|
||||
[--sentences-input SENTENCES_FILE] [--sentences-output OUTPUT_FILE] [--sentences-only | --no-sentences-only]
|
||||
[--includes | --no-includes] [-v | --verbose | --no-verbose] [-q | --quiet | --no-quiet]
|
||||
[--includes | --no-includes] [--add-empty | --no-add-empty] [-v | --verbose | --no-verbose] [-q | --quiet | --no-quiet]
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
@@ -31,6 +31,8 @@ options:
|
||||
generate only sentences from names (does not read input image)
|
||||
--includes, --no-includes
|
||||
use #include preprocessor in GLSL (forge)
|
||||
--add-empty, --no-add-empty
|
||||
add EMPTY tile at start of tileset if missing
|
||||
-v, --verbose, --no-verbose
|
||||
more verbose logging
|
||||
-q, --quiet, --no-quiet
|
||||
@@ -83,7 +85,7 @@ release-% release major/minor/patch
|
||||
### TODO
|
||||
|
||||
* [x] Initial implementation
|
||||
* [ ] Generate a separate sentences file
|
||||
* [x] Generate a separate sentences file
|
||||
* [ ] Custom height glyph map
|
||||
* [ ] Custom width glyph map
|
||||
* [ ] separated sets/patterns
|
||||
|
||||
@@ -79,10 +79,7 @@ class Generator:
|
||||
lines = []
|
||||
|
||||
if self.with_includes and self.with_functions:
|
||||
lines += [
|
||||
f"#include {self.target_path.name}",
|
||||
""
|
||||
]
|
||||
lines += [f"#include {self.target_path.name}", ""]
|
||||
|
||||
lines += [
|
||||
GLSL_SENTENCES_PREFIX.format(self.target_name.upper()),
|
||||
|
||||
@@ -17,6 +17,7 @@ class Parameters:
|
||||
target_sentences_path: str | None = None
|
||||
includes: bool = False
|
||||
sentences_only: bool = False
|
||||
add_empty: bool = False
|
||||
verbose: bool = False
|
||||
quiet: bool = False
|
||||
|
||||
@@ -98,6 +99,12 @@ def parse_parameters(args: typing.Sequence[str]) -> Parameters:
|
||||
default=default_values.verbose,
|
||||
help="use #include preprocessor in GLSL (forge)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--add-empty",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=default_values.verbose,
|
||||
help="add EMPTY tile at start of tileset if missing",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
|
||||
@@ -13,6 +13,8 @@ from .set import GlyphSet
|
||||
if typing.TYPE_CHECKING:
|
||||
from .params import Parameters
|
||||
|
||||
MAX_GLYPHS = 256
|
||||
|
||||
|
||||
class Reader:
|
||||
def __init__(self, params: Parameters) -> None:
|
||||
@@ -28,18 +30,29 @@ class Reader:
|
||||
if params.source_sentences_path
|
||||
else None
|
||||
)
|
||||
self.load_sentences = params.source_sentences_path is not None
|
||||
self.add_empty = params.add_empty
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def read(self) -> tuple[list[Glyph], list[GlyphSet], list[Sentence]]:
|
||||
glyphs = self.__read_image()
|
||||
names = self.__read_names()
|
||||
sets = self.__read_sets()
|
||||
sentences = self.__read_sentences(names)
|
||||
|
||||
for glyph, name in zip(glyphs, names, strict=False):
|
||||
glyph.name = name
|
||||
|
||||
if self.add_empty and "EMPTY" not in names:
|
||||
if len(glyphs) >= MAX_GLYPHS:
|
||||
self.log.error(
|
||||
"Cannot add missing EMPTY glyph in full %d glyphmap", MAX_GLYPHS
|
||||
)
|
||||
sys.exit(1)
|
||||
glyphs.insert(0, Glyph(data=[0] * 4, name="EMPTY"))
|
||||
names.insert(0, "EMPTY")
|
||||
|
||||
sets = self.__read_sets()
|
||||
|
||||
sentences = self.__read_sentences(names)
|
||||
|
||||
return glyphs, sets, sentences
|
||||
|
||||
def read_sentences(self) -> list[Sentence]:
|
||||
@@ -54,9 +67,10 @@ class Reader:
|
||||
"Input image is not an 8x8 multiple (%dx%d)", img.width, img.height
|
||||
)
|
||||
sys.exit(1)
|
||||
if img.width * img.height > 256 * 8 * 8:
|
||||
if img.width * img.height > MAX_GLYPHS * 8 * 8:
|
||||
self.log.error(
|
||||
"Input image too big, it must have at maximum 256 tiles (currently: %d)",
|
||||
"Input image too big, it must have at maximum %d tiles (currently: %d)",
|
||||
MAX_GLYPHS,
|
||||
(img.width * img.height) // (8 * 8),
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user