mirror of https://github.com/minetest/minetest.git
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.
This commit is contained in:
parent
5ca5630a11
commit
d0d45fcd78
|
@ -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,
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 263 B |
44
src/tile.cpp
44
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=\""<<part_of_name
|
||||
<<"\", cancelling."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Strfnd sf(part_of_name);
|
||||
sf.next(":");
|
||||
u32 w0 = stoi(sf.next(":"));
|
||||
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 "
|
||||
|
|
Loading…
Reference in New Issue