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