From d0d45fcd7899d3f489a3f38d935db9397155b9d2 Mon Sep 17 00:00:00 2001 From: Luke Puchner-Hardman Date: Tue, 23 Sep 2014 14:39:34 +0200 Subject: [PATCH 1/3] Added "[sheet" to the texture special commands. "[sheet:W:H:X:Y" assumes the base image is a tilesheet with W*H tiles on it and crops to the tile at position X,Y. Basically it works like "[verticalframe" but in 2d. For testing, I combined the four default_chest images into one. --- games/minimal/mods/default/init.lua | 10 ++-- .../mods/default/textures/default_chest.png | Bin 0 -> 263 bytes src/tile.cpp | 44 ++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 games/minimal/mods/default/textures/default_chest.png diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index 038bf9abc..076f2e6ce 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -1135,8 +1135,9 @@ minetest.register_node("default:sign_wall", { minetest.register_node("default:chest", { description = "Chest", - tiles ={"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"}, + tiles ={"default_chest.png^[sheet:2:2:0:0", "default_chest.png^[sheet:2:2:0:0", + "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:0", + "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:0:1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, @@ -1168,8 +1169,9 @@ end minetest.register_node("default:chest_locked", { description = "Locked Chest", - tiles ={"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"}, + tiles ={"default_chest.png^[sheet:2:2:0:0", "default_chest.png^[sheet:2:2:0:0", + "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:0", + "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, diff --git a/games/minimal/mods/default/textures/default_chest.png b/games/minimal/mods/default/textures/default_chest.png new file mode 100644 index 0000000000000000000000000000000000000000..9746a3fd9396e8d318be2674deeee14427c74586 GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1SJ1Ryj={WI14-?iy0WWg+Z8+Vb&Z8pdfpR zr>`sfJx+0MH8sl}#uI=-%RF5iLp+Wr=VT--&`d~7NJy}7*iyvK7If9v(BQ&B_9aa0 zLRa|wFMba zSA!3-H#G@glyEu1xNgHSExC@}s|pSTK9tE&(0#fuX6DHQ2M!2WO!P99O4CR*o;B;| zgWIj4Tedb#oIAZuY)}0B^DAF+CSK6u+aP5dCC@YM7X!nQk18x*_VhLZUCiL=>gTe~ HDWM4fnuc4; literal 0 HcmV?d00001 diff --git a/src/tile.cpp b/src/tile.cpp index ebef77fb9..e152c6fab 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1588,6 +1588,50 @@ bool TextureSource::generateImagePart(std::string part_of_name, << filename << "\"."; } } + /* + [sheet:W:H:X:Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (part_of_name.substr(0,7) == "[sheet:") + { + if(baseimg == NULL){ + errorstream<<"generateImagePart(): baseimg != NULL " + <<"for part_of_name=\""< img_dim = baseimg->getDimension(); + core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_dim); + if(!img){ + errorstream<<"generateImagePart(): Could not create image " + <<"for part_of_name=\""<fill(video::SColor(0,0,0,0)); + v2u32 vdim(tile_dim); + core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } else { errorstream<<"generateImagePart(): Invalid " From 1dcbd7add86b9f577f32bb2f8e4988143776d80e Mon Sep 17 00:00:00 2001 From: Luke Puchner-Hardman Date: Tue, 23 Sep 2014 16:20:00 +0200 Subject: [PATCH 2/3] Changed syntax and added documentation for texture special command "[sheet". --- doc/lua_api.txt | 4 ++++ games/minimal/mods/default/init.lua | 12 ++++++------ src/tile.cpp | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 0cdca506f..8bf38dbf6 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -262,6 +262,10 @@ Advanced texture modifiers: Apply a mask to the base image. The mask is applied using binary AND. + [sheet:x:, + Retrieves a tile at position x,y from the base image + which it assumes to be a tilesheet with dimensions w,h. + Sounds ------- Only OGG Vorbis files are supported. diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index 076f2e6ce..33c863d3f 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -1135,9 +1135,9 @@ minetest.register_node("default:sign_wall", { minetest.register_node("default:chest", { description = "Chest", - tiles ={"default_chest.png^[sheet:2:2:0:0", "default_chest.png^[sheet:2:2:0:0", - "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:0", - "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:0:1"}, + tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:0,1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, @@ -1169,9 +1169,9 @@ end minetest.register_node("default:chest_locked", { description = "Locked Chest", - tiles ={"default_chest.png^[sheet:2:2:0:0", "default_chest.png^[sheet:2:2:0:0", - "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:0", - "default_chest.png^[sheet:2:2:1:0", "default_chest.png^[sheet:2:2:1:1"}, + tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, diff --git a/src/tile.cpp b/src/tile.cpp index e152c6fab..b1fe28961 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1589,7 +1589,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, } } /* - [sheet:W:H:X:Y + [sheet:WxH:X,Y Retrieves a tile at position X,Y (in tiles) from the base image it assumes to be a tilesheet with dimensions W,H (in tiles). @@ -1605,9 +1605,9 @@ bool TextureSource::generateImagePart(std::string part_of_name, Strfnd sf(part_of_name); sf.next(":"); - u32 w0 = stoi(sf.next(":")); + u32 w0 = stoi(sf.next("x")); u32 h0 = stoi(sf.next(":")); - u32 x0 = stoi(sf.next(":")); + u32 x0 = stoi(sf.next(",")); u32 y0 = stoi(sf.next(":")); core::dimension2d img_dim = baseimg->getDimension(); From 7c0747b32318f57cf46be895794102eaaebccd71 Mon Sep 17 00:00:00 2001 From: Luke Puchner-Hardman Date: Tue, 23 Sep 2014 14:39:34 +0200 Subject: [PATCH 3/3] Added "[sheet" to the texture special commands. "[sheet:WxH:X,Y" assumes the base image is a tilesheet with W*H tiles on it and crops to the tile at position X,Y. Basically it works like "[verticalframe" but in 2d. For testing, I combined the four default_chest images into one. --- doc/lua_api.txt | 4 ++ games/minimal/mods/default/init.lua | 10 ++-- .../mods/default/textures/default_chest.png | Bin 0 -> 263 bytes src/tile.cpp | 44 ++++++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 games/minimal/mods/default/textures/default_chest.png diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 0cdca506f..8bf38dbf6 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -262,6 +262,10 @@ Advanced texture modifiers: Apply a mask to the base image. The mask is applied using binary AND. + [sheet:x:, + Retrieves a tile at position x,y from the base image + which it assumes to be a tilesheet with dimensions w,h. + Sounds ------- Only OGG Vorbis files are supported. diff --git a/games/minimal/mods/default/init.lua b/games/minimal/mods/default/init.lua index 038bf9abc..33c863d3f 100644 --- a/games/minimal/mods/default/init.lua +++ b/games/minimal/mods/default/init.lua @@ -1135,8 +1135,9 @@ minetest.register_node("default:sign_wall", { minetest.register_node("default:chest", { description = "Chest", - tiles ={"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"}, + tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:0,1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, @@ -1168,8 +1169,9 @@ end minetest.register_node("default:chest_locked", { description = "Locked Chest", - tiles ={"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", - "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"}, + tiles ={"default_chest.png^[sheet:2x2:0,0", "default_chest.png^[sheet:2x2:0,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,0", + "default_chest.png^[sheet:2x2:1,0", "default_chest.png^[sheet:2x2:1,1"}, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, diff --git a/games/minimal/mods/default/textures/default_chest.png b/games/minimal/mods/default/textures/default_chest.png new file mode 100644 index 0000000000000000000000000000000000000000..9746a3fd9396e8d318be2674deeee14427c74586 GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1SJ1Ryj={WI14-?iy0WWg+Z8+Vb&Z8pdfpR zr>`sfJx+0MH8sl}#uI=-%RF5iLp+Wr=VT--&`d~7NJy}7*iyvK7If9v(BQ&B_9aa0 zLRa|wFMba zSA!3-H#G@glyEu1xNgHSExC@}s|pSTK9tE&(0#fuX6DHQ2M!2WO!P99O4CR*o;B;| zgWIj4Tedb#oIAZuY)}0B^DAF+CSK6u+aP5dCC@YM7X!nQk18x*_VhLZUCiL=>gTe~ HDWM4fnuc4; literal 0 HcmV?d00001 diff --git a/src/tile.cpp b/src/tile.cpp index ebef77fb9..b1fe28961 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1588,6 +1588,50 @@ bool TextureSource::generateImagePart(std::string part_of_name, << filename << "\"."; } } + /* + [sheet:WxH:X,Y + Retrieves a tile at position X,Y (in tiles) + from the base image it assumes to be a + tilesheet with dimensions W,H (in tiles). + */ + else if (part_of_name.substr(0,7) == "[sheet:") + { + if(baseimg == NULL){ + errorstream<<"generateImagePart(): baseimg != NULL " + <<"for part_of_name=\""< img_dim = baseimg->getDimension(); + core::dimension2d tile_dim(v2u32(img_dim) / v2u32(w0, h0)); + + video::IImage *img = driver->createImage( + video::ECF_A8R8G8B8, tile_dim); + if(!img){ + errorstream<<"generateImagePart(): Could not create image " + <<"for part_of_name=\""<fill(video::SColor(0,0,0,0)); + v2u32 vdim(tile_dim); + core::rect rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim); + baseimg->copyToWithAlpha(img, v2s32(0), rect, + video::SColor(255,255,255,255), NULL); + + // Replace baseimg + baseimg->drop(); + baseimg = img; + } else { errorstream<<"generateImagePart(): Invalid "