Added "[sheet" to the texture special commands.
authorLuke Puchner-Hardman <x.lukk3.x@gmail.com>
Tue, 23 Sep 2014 12:39:34 +0000 (14:39 +0200)
committersfan5 <sfan5@live.de>
Mon, 2 Jan 2017 14:28:06 +0000 (15:28 +0100)
"[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
games/minimal/mods/default/init.lua
games/minimal/mods/default/textures/default_chest.png [new file with mode: 0644]
games/minimal/mods/default/textures/default_chest_front.png [deleted file]
games/minimal/mods/default/textures/default_chest_lock.png [deleted file]
games/minimal/mods/default/textures/default_chest_side.png [deleted file]
games/minimal/mods/default/textures/default_chest_top.png [deleted file]
src/client/tile.cpp

index d2ddc635b3c04d9de6e50d9fce412887a34a75af..648a29303113973323f297b78cd7a34a031b5b48 100644 (file)
@@ -403,6 +403,11 @@ Apply a mask to the base image.
 
 The mask is applied using binary AND.
 
+#### `[sheet:<w>x<h>:<x>,<y>`
+Retrieves a tile at position x,y from the base image
+which it assumes to be a tilesheet with dimensions w,h.
+
+
 #### `[colorize:<color>:<ratio>`
 Colorize the textures with the given color.
 `<color>` is specified as a `ColorString`.
index bff7860e36f54d9d4cda9893525b20fa53c683a6..f532e7193e6a35d26527c39aba2c4aac48bb6979 100644 (file)
@@ -1130,8 +1130,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,
@@ -1164,8 +1165,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 (file)
index 0000000..9746a3f
Binary files /dev/null and b/games/minimal/mods/default/textures/default_chest.png differ
diff --git a/games/minimal/mods/default/textures/default_chest_front.png b/games/minimal/mods/default/textures/default_chest_front.png
deleted file mode 100644 (file)
index 55b076c..0000000
Binary files a/games/minimal/mods/default/textures/default_chest_front.png and /dev/null differ
diff --git a/games/minimal/mods/default/textures/default_chest_lock.png b/games/minimal/mods/default/textures/default_chest_lock.png
deleted file mode 100644 (file)
index 4b2d1af..0000000
Binary files a/games/minimal/mods/default/textures/default_chest_lock.png and /dev/null differ
diff --git a/games/minimal/mods/default/textures/default_chest_side.png b/games/minimal/mods/default/textures/default_chest_side.png
deleted file mode 100644 (file)
index ae4847c..0000000
Binary files a/games/minimal/mods/default/textures/default_chest_side.png and /dev/null differ
diff --git a/games/minimal/mods/default/textures/default_chest_top.png b/games/minimal/mods/default/textures/default_chest_top.png
deleted file mode 100644 (file)
index ac41551..0000000
Binary files a/games/minimal/mods/default/textures/default_chest_top.png and /dev/null differ
index 7f7535df629491431d53edecb441a828457f1016..4d2166342893fef5e70dc3ecfdd18dc94b74916c 100644 (file)
@@ -1827,6 +1827,49 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                                baseimg->setPixel(x, y, c);
                        }
                }
+               /*
+                       [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=\"" << part_of_name
+                                               << "\", cancelling." << std::endl;
+                               return false;
+                       }
+
+                       Strfnd sf(part_of_name);
+                       sf.next(":");
+                       u32 w0 = stoi(sf.next("x"));
+                       u32 h0 = stoi(sf.next(":"));
+                       u32 x0 = stoi(sf.next(","));
+                       u32 y0 = stoi(sf.next(":"));
+
+                       core::dimension2d<u32> img_dim = baseimg->getDimension();
+                       core::dimension2d<u32> 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=\"" << part_of_name
+                                               << "\", cancelling." << std::endl;
+                               return false;
+                       }
+
+                       img->fill(video::SColor(0,0,0,0));
+                       v2u32 vdim(tile_dim);
+                       core::rect<s32> 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 "