summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/makefile11
-rw-r--r--light-client/assets/.gitignore1
-rw-r--r--light-client/assets/items.ini2
-rw-r--r--light-client/assets/tiles.ini2
-rw-r--r--light-client/makefile34
-rw-r--r--light-client/src/atlas.rs6
-rw-r--r--light-client/tools/src/bin/tex_compose.rs138
-rw-r--r--light-client/tools/src/bin/tex_export.rs2
-rw-r--r--light-client/tools/src/bin/tex_import.rs2
-rw-r--r--light-client/tools/src/bin/tex_pack.rs3
-rw-r--r--makefile15
11 files changed, 188 insertions, 28 deletions
diff --git a/client/makefile b/client/makefile
new file mode 100644
index 00000000..e448e5ac
--- /dev/null
+++ b/client/makefile
@@ -0,0 +1,11 @@
+.PHONY: assets clean all
+all: assets
+assets: menu/book/book_1.webp
+
+clean:
+ rm -f menu/book/book_*.webp
+
+menu/book/book_1.webp:
+ @echo Downloading recipe book...
+ @mkdir -p menu/book
+ @curl -L https://s.metamuffin.org/static/hurrycurry/book.webp.tar.zst | tar -xC menu/book
diff --git a/light-client/assets/.gitignore b/light-client/assets/.gitignore
index 96a451b4..89bda45f 100644
--- a/light-client/assets/.gitignore
+++ b/light-client/assets/.gitignore
@@ -1,3 +1,4 @@
*.png
/atlas.ta
/atlas.meta.csv
+/sprites
diff --git a/light-client/assets/items.ini b/light-client/assets/items.ini
index bb8108cd..f62c8e77 100644
--- a/light-client/assets/items.ini
+++ b/light-client/assets/items.ini
@@ -1,2 +1,2 @@
-tomato-slice-plate=plate,tomato-slice+5
+tomato-slice-plate=plate,tomato_slice~x8~y16
diff --git a/light-client/assets/tiles.ini b/light-client/assets/tiles.ini
index fcc0c28a..698549c0 100644
--- a/light-client/assets/tiles.ini
+++ b/light-client/assets/tiles.ini
@@ -21,4 +21,4 @@ wall=wns:wall_wns
wall=ens:wall_wns~hflip
wall=wens:wall_wens
-tomato-crate=crate_back,tomato,crate_front
+tomato-crate=crate_back,tomato~x8~y6,crate_front
diff --git a/light-client/makefile b/light-client/makefile
index 39199caa..4f900412 100644
--- a/light-client/makefile
+++ b/light-client/makefile
@@ -1,21 +1,33 @@
-ALL_TA = $(shell find textures/tiles -name '*.ta')
-ALL_PNG = $(shell find textures/tiles -name '*.png')
-ALL_TA_IMPORT = $(patsubst %.import.png,%.ta,$(shell find textures/tiles -name '*.import.png'))
-ALL_PNG_EXPORT = $(patsubst %.ta,%.png,$(ALL_TA))
+SPRITES = $(shell find assets/sprites -name '*.ta')
+SPRITES_PNG = $(patsubst %.ta,%.png,$(SPRITES))
+
+TEXTURES = $(shell find assets/textures -name '*.ta')
+TEXTURES_PNG = $(patsubst %.ta,%.png,$(TEXTURES))
+TEXTURES_IMPORT_PNG = $(patsubst %.import.png,%.ta,$(shell find assets/textures -name '*.import.png'))
+
+PNG = $(shell find assets/textures -name '*.png')
.PHONY: tex_pack tex_export tex_import clean
-tex_pack: textures/atlas.ta
-tex_import: $(ALL_TA_IMPORT)
-tex_export: $(ALL_PNG_EXPORT)
+tex_pack: assets/atlas.ta
+tex_import: $(TEXTURES_IMPORT_PNG)
+tex_export: $(TEXTURES_PNG) $(SPRITES_PNG) assets/atlas.png
clean:
- rm -f $(ALL_PNG)
- rm -f textures/atlas.ta textures/atlas.meta.csv
+ rm -f $(PNG)
+ rm -f $(SPRITES)
+ rm -f assets/atlas.ta assets/atlas.meta.csv
%.ta: %.import.png
../target/release/tex_import $< $@
%.png: %.ta
../target/release/tex_export $< $@
-textures/atlas.ta textures/atlas.meta.csv: $(ALL_TA)
- ../target/release/tex_pack textures/atlas.ta textures/atlas.meta.csv $^
+assets/sprites/items/all: assets/items.ini $(TEXTURES)
+ @mkdir -p assets/sprites/items
+ ../target/release/tex_compose $< assets/textures assets/sprites/items
+assets/sprites/tiles/all: assets/tiles.ini $(TEXTURES)
+ @mkdir -p assets/sprites/tiles
+ ../target/release/tex_compose $< assets/textures assets/sprites/tiles
+
+assets/atlas.ta assets/atlas.meta.csv: assets/sprites/items/all assets/sprites/tiles/all
+ ../target/release/tex_pack assets/atlas.ta assets/atlas.meta.csv $(SPRITES)
diff --git a/light-client/src/atlas.rs b/light-client/src/atlas.rs
index 4a39b649..6d3f7645 100644
--- a/light-client/src/atlas.rs
+++ b/light-client/src/atlas.rs
@@ -47,7 +47,7 @@ pub struct DrawItem {
impl<'a> SpriteRenderer<'a> {
pub fn init(texture_creator: &'a TextureCreator<WindowContext>) -> Self {
- let palette = include_str!("../textures/palette.csv")
+ let palette = include_str!("../assets/palette.csv")
.split('\n')
.filter(|l| !l.is_empty())
.map(|s| {
@@ -66,7 +66,7 @@ impl<'a> SpriteRenderer<'a> {
let mut texels = vec![255; 1024 * 1024 * 4];
- for (y, line) in include_str!("../textures/atlas.ta").lines().enumerate() {
+ for (y, line) in include_str!("../assets/atlas.ta").lines().enumerate() {
if line.is_empty() {
continue;
}
@@ -102,7 +102,7 @@ impl<'a> SpriteRenderer<'a> {
}
pub fn set_sprite_map(&mut self, data: ClientGamedata) {
- let meta = include_str!("../textures/atlas.meta.csv")
+ let meta = include_str!("../assets/atlas.meta.csv")
.lines()
.filter(|l| !l.is_empty())
.map(|l| {
diff --git a/light-client/tools/src/bin/tex_compose.rs b/light-client/tools/src/bin/tex_compose.rs
new file mode 100644
index 00000000..77e69c45
--- /dev/null
+++ b/light-client/tools/src/bin/tex_compose.rs
@@ -0,0 +1,138 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+use clap::Parser;
+use std::{
+ collections::HashMap,
+ fs::{read_to_string, File},
+ io::{BufRead, BufReader, BufWriter, Write},
+ path::PathBuf,
+};
+
+#[derive(Parser)]
+struct Args {
+ catalogue: PathBuf,
+ texture_dir: PathBuf,
+ output_dir: PathBuf,
+}
+
+fn main() {
+ let Args {
+ catalogue,
+ texture_dir,
+ output_dir,
+ } = Args::parse();
+
+ for line in read_to_string(catalogue).unwrap().lines() {
+ let (line, _) = line.split_once(";").unwrap_or((line, ""));
+ let line = line.trim();
+ if line.is_empty() {
+ continue;
+ }
+
+ let (name, rest) = line.split_once("=").unwrap();
+ let (connects, rest) = rest.split_once(":").unwrap_or(("", rest));
+ eprintln!(" compose {name:?} ({connects})");
+
+ let mut texels = HashMap::new();
+
+ for part in rest.split(",") {
+ let mut mods = part.split("~");
+ let texname = mods.next().unwrap();
+
+ let mut hflip = false;
+ let mut vflip = true;
+ let mut xoff = 0;
+ let mut yoff = 0;
+
+ for m in mods {
+ if m == "hflip" {
+ hflip = !hflip
+ }
+ if m == "vflip" {
+ vflip = !vflip
+ }
+ if let Some(m) = m.strip_prefix("x") {
+ xoff += m.parse::<i32>().unwrap();
+ }
+ if let Some(m) = m.strip_prefix("y") {
+ yoff += m.parse::<i32>().unwrap();
+ }
+ }
+
+ let texpath = texture_dir.join(texname).with_extension("ta");
+ eprintln!(" + {texpath:?}");
+ let file = BufReader::new(File::open(&texpath).unwrap());
+ let tex = file.lines().map(Result::unwrap).collect::<Vec<String>>();
+ let (width, height) = (tex[0].chars().count(), tex.len());
+
+ for (mut y, line) in tex.iter().enumerate() {
+ if line.is_empty() {
+ continue;
+ }
+ if vflip {
+ y = height - y - 1
+ }
+ for (mut x, char) in line.chars().enumerate() {
+ if hflip {
+ x = width - x - 1
+ }
+ let e = texels
+ .entry((x as i32 + xoff, y as i32 + yoff))
+ .or_insert(' ');
+ if char != ' ' {
+ *e = char
+ }
+ }
+ }
+ }
+
+ let mut min_x = 0;
+ let mut min_y = 0;
+ let mut max_x = 0;
+ let mut max_y = 0;
+ for (x, y) in texels.keys() {
+ min_x = min_x.min(*x);
+ min_y = min_y.min(*y);
+ max_x = max_x.max(*x);
+ max_y = max_y.max(*y);
+ }
+
+ let width = max_x - min_x;
+ let height = max_y - min_y;
+
+ let mut name = name.to_string();
+ if !connects.is_empty() {
+ name += "+";
+ name += connects;
+ }
+ let outpath = output_dir.join(name).with_extension("ta");
+ let mut output = BufWriter::new(File::create(outpath).unwrap());
+
+ for y in 0..height {
+ for x in 0..width {
+ write!(
+ output,
+ "{}",
+ texels.get(&(x + min_x, max_y - y - 1)).unwrap_or(&' ')
+ )
+ .unwrap();
+ }
+ writeln!(output).unwrap();
+ }
+ }
+}
diff --git a/light-client/tools/src/bin/tex_export.rs b/light-client/tools/src/bin/tex_export.rs
index d325d912..248990e6 100644
--- a/light-client/tools/src/bin/tex_export.rs
+++ b/light-client/tools/src/bin/tex_export.rs
@@ -36,7 +36,7 @@ fn main() {
output: out_path,
} = Args::parse();
- let palette = include_str!("../../../textures/palette.csv")
+ let palette = include_str!("../../../assets/palette.csv")
.split('\n')
.filter(|l| !l.is_empty())
.map(|s| {
diff --git a/light-client/tools/src/bin/tex_import.rs b/light-client/tools/src/bin/tex_import.rs
index 21d1403e..a5dad499 100644
--- a/light-client/tools/src/bin/tex_import.rs
+++ b/light-client/tools/src/bin/tex_import.rs
@@ -33,7 +33,7 @@ struct Args {
fn main() {
let Args { input, output } = Args::parse();
- let palette = include_str!("../../../textures/palette.csv")
+ let palette = include_str!("../../../assets/palette.csv")
.split('\n')
.filter(|l| !l.is_empty())
.map(|s| {
diff --git a/light-client/tools/src/bin/tex_pack.rs b/light-client/tools/src/bin/tex_pack.rs
index aadd9e16..e6d73ab3 100644
--- a/light-client/tools/src/bin/tex_pack.rs
+++ b/light-client/tools/src/bin/tex_pack.rs
@@ -45,13 +45,14 @@ fn main() {
let mut texels = vec![vec![' '; atlas_size]; atlas_size];
let mut metadata = Vec::new();
+ println!(" savepack {atlas_out:?}");
for path in inputs {
let file = BufReader::new(File::open(&path).unwrap());
let tex = file.lines().map(Result::unwrap).collect::<Vec<String>>();
let name = path.file_stem().unwrap().to_str().unwrap().to_string();
let (width, height) = (tex[0].chars().count(), tex.len());
- println!("adding {width}x{height} {name}");
+ println!(" + {width}x{height} {name}");
if cursor_x + width > atlas_size {
cursor_y += row_height;
diff --git a/makefile b/makefile
index b9ddea19..873063aa 100644
--- a/makefile
+++ b/makefile
@@ -1,10 +1,7 @@
-.PHONY: client-assets clean
-client-assets: client/menu/book/book_1.webp
+.PHONY: all client light-client
+all: client light-client
-clean:
- rm client/menu/book/book_*.webp
-
-client/menu/book/book_1.webp:
- @echo Downloading recipe book...
- @mkdir -p client/menu/book
- @curl -L https://s.metamuffin.org/static/hurrycurry/book.webp.tar.zst | tar -xC client/menu/book
+client:
+ make -C client all
+light-client:
+ make -C light-client all