Textures: introduce world-align overrides (#12540)

Many games do not care about world align textures, however texture packs should have the capabilities to change that if they have suitable textures. This commmit now introduces a node property override for world-align in particular to force a certain scale on the selected override tiles.
This commit is contained in:
SmallJoker 2022-08-13 08:52:16 +02:00 committed by GitHub
parent 8bf1609ccc
commit 023a1c2427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 52 deletions

@ -204,10 +204,13 @@ Here are targets you can choose from:
| special6 | The sixth entry in the special_tiles list | | special6 | The sixth entry in the special_tiles list |
| inventory | The inventory texture | | inventory | The inventory texture |
| wield | The texture used when held by the player | | wield | The texture used when held by the player |
| align_world=N | Overrides the "world align" behaviour of tiles ¹ |
Nodes support all targets, but other items only support 'inventory' Nodes support all targets, but other items only support 'inventory'
and 'wield'. and 'wield'.
¹ : `N` is an integer [0,255]. Sets align_style = "world" and scale = N on the tile, refer to lua_api.txt for details.
### Using the special targets ### Using the special targets
The special* targets only apply to specific drawtypes: The special* targets only apply to specific drawtypes:

@ -1445,44 +1445,52 @@ void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &o
ContentFeatures &nodedef = m_content_features[id]; ContentFeatures &nodedef = m_content_features[id];
auto apply = [&] (TileDef &tile) {
tile.name = texture_override.texture;
if (texture_override.world_scale > 0) {
tile.align_style = ALIGN_STYLE_WORLD;
tile.scale = texture_override.world_scale;
}
};
// Override tiles // Override tiles
if (texture_override.hasTarget(OverrideTarget::TOP)) if (texture_override.hasTarget(OverrideTarget::TOP))
nodedef.tiledef[0].name = texture_override.texture; apply(nodedef.tiledef[0]);
if (texture_override.hasTarget(OverrideTarget::BOTTOM)) if (texture_override.hasTarget(OverrideTarget::BOTTOM))
nodedef.tiledef[1].name = texture_override.texture; apply(nodedef.tiledef[1]);
if (texture_override.hasTarget(OverrideTarget::RIGHT)) if (texture_override.hasTarget(OverrideTarget::RIGHT))
nodedef.tiledef[2].name = texture_override.texture; apply(nodedef.tiledef[2]);
if (texture_override.hasTarget(OverrideTarget::LEFT)) if (texture_override.hasTarget(OverrideTarget::LEFT))
nodedef.tiledef[3].name = texture_override.texture; apply(nodedef.tiledef[3]);
if (texture_override.hasTarget(OverrideTarget::BACK)) if (texture_override.hasTarget(OverrideTarget::BACK))
nodedef.tiledef[4].name = texture_override.texture; apply(nodedef.tiledef[4]);
if (texture_override.hasTarget(OverrideTarget::FRONT)) if (texture_override.hasTarget(OverrideTarget::FRONT))
nodedef.tiledef[5].name = texture_override.texture; apply(nodedef.tiledef[5]);
// Override special tiles, if applicable // Override special tiles, if applicable
if (texture_override.hasTarget(OverrideTarget::SPECIAL_1)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_1))
nodedef.tiledef_special[0].name = texture_override.texture; apply(nodedef.tiledef_special[0]);
if (texture_override.hasTarget(OverrideTarget::SPECIAL_2)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_2))
nodedef.tiledef_special[1].name = texture_override.texture; apply(nodedef.tiledef_special[1]);
if (texture_override.hasTarget(OverrideTarget::SPECIAL_3)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_3))
nodedef.tiledef_special[2].name = texture_override.texture; apply(nodedef.tiledef_special[2]);
if (texture_override.hasTarget(OverrideTarget::SPECIAL_4)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_4))
nodedef.tiledef_special[3].name = texture_override.texture; apply(nodedef.tiledef_special[3]);
if (texture_override.hasTarget(OverrideTarget::SPECIAL_5)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_5))
nodedef.tiledef_special[4].name = texture_override.texture; apply(nodedef.tiledef_special[4]);
if (texture_override.hasTarget(OverrideTarget::SPECIAL_6)) if (texture_override.hasTarget(OverrideTarget::SPECIAL_6))
nodedef.tiledef_special[5].name = texture_override.texture; apply(nodedef.tiledef_special[5]);
} }
} }

@ -26,6 +26,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define override_cast static_cast<override_t> #define override_cast static_cast<override_t>
static const std::map<std::string, OverrideTarget> override_LUT = {
{ "top", OverrideTarget::TOP },
{ "bottom", OverrideTarget::BOTTOM },
{ "left", OverrideTarget::LEFT },
{ "right", OverrideTarget::RIGHT },
{ "front", OverrideTarget::FRONT },
{ "back", OverrideTarget::BACK },
{ "inventory", OverrideTarget::INVENTORY },
{ "wield", OverrideTarget::WIELD },
{ "special1", OverrideTarget::SPECIAL_1 },
{ "special2", OverrideTarget::SPECIAL_2 },
{ "special3", OverrideTarget::SPECIAL_3 },
{ "special4", OverrideTarget::SPECIAL_4 },
{ "special5", OverrideTarget::SPECIAL_5 },
{ "special6", OverrideTarget::SPECIAL_6 },
{ "sides", OverrideTarget::SIDES },
{ "all", OverrideTarget::ALL_FACES },
{ "*", OverrideTarget::ALL_FACES }
};
TextureOverrideSource::TextureOverrideSource(std::string filepath) TextureOverrideSource::TextureOverrideSource(std::string filepath)
{ {
std::ifstream infile(filepath.c_str()); std::ifstream infile(filepath.c_str());
@ -41,8 +61,9 @@ TextureOverrideSource::TextureOverrideSource(std::string filepath)
if (line.empty() || line[0] == '#') if (line.empty() || line[0] == '#')
continue; continue;
// Format: mod_name:item_name target1[,...] texture_name.png
std::vector<std::string> splitted = str_split(line, ' '); std::vector<std::string> splitted = str_split(line, ' ');
if (splitted.size() != 3) { if (splitted.size() < 3) {
warningstream << filepath << ":" << line_index warningstream << filepath << ":" << line_index
<< " Syntax error in texture override \"" << line << " Syntax error in texture override \"" << line
<< "\": Expected 3 arguments, got " << splitted.size() << "\": Expected 3 arguments, got " << splitted.size()
@ -57,45 +78,31 @@ TextureOverrideSource::TextureOverrideSource(std::string filepath)
// Parse the target mask // Parse the target mask
std::vector<std::string> targets = str_split(splitted[1], ','); std::vector<std::string> targets = str_split(splitted[1], ',');
for (const std::string &target : targets) { for (const std::string &target : targets) {
if (target == "top") std::vector<std::string> kvpair = str_split(target, '=');
texture_override.target |= override_cast(OverrideTarget::TOP); if (kvpair.size() == 2) {
else if (target == "bottom") // Key-value pairs
texture_override.target |= override_cast(OverrideTarget::BOTTOM); if (kvpair[0] == "align_world") {
else if (target == "left") // Global textures
texture_override.target |= override_cast(OverrideTarget::LEFT); texture_override.world_scale = stoi(kvpair[1], 0, U8_MAX);
else if (target == "right") continue;
texture_override.target |= override_cast(OverrideTarget::RIGHT); }
else if (target == "front")
texture_override.target |= override_cast(OverrideTarget::FRONT);
else if (target == "back")
texture_override.target |= override_cast(OverrideTarget::BACK);
else if (target == "inventory")
texture_override.target |= override_cast(OverrideTarget::INVENTORY);
else if (target == "wield")
texture_override.target |= override_cast(OverrideTarget::WIELD);
else if (target == "special1")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_1);
else if (target == "special2")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_2);
else if (target == "special3")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_3);
else if (target == "special4")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_4);
else if (target == "special5")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_5);
else if (target == "special6")
texture_override.target |= override_cast(OverrideTarget::SPECIAL_6);
else if (target == "sides")
texture_override.target |= override_cast(OverrideTarget::SIDES);
else if (target == "all" || target == "*")
texture_override.target |= override_cast(OverrideTarget::ALL_FACES);
else {
// Report invalid target
warningstream << filepath << ":" << line_index
<< " Syntax error in texture override \"" << line
<< "\": Unknown target \"" << target << "\""
<< std::endl;
} }
if (kvpair.size() == 1) {
// Regular override flags
auto pair = override_LUT.find(target);
if (pair != override_LUT.end()) {
texture_override.target |= override_cast(pair->second);
continue;
}
}
// Report invalid target
warningstream << filepath << ":" << line_index
<< " Syntax error in texture override \"" << line
<< "\": Unknown target \"" << target << "\""
<< std::endl;
} }
// If there are no valid targets, skip adding this override // If there are no valid targets, skip adding this override

@ -57,7 +57,8 @@ struct TextureOverride
{ {
std::string id; std::string id;
std::string texture; std::string texture;
override_t target; override_t target = 0;
u8 world_scale = 0;
// Helper function for checking if an OverrideTarget is found in // Helper function for checking if an OverrideTarget is found in
// a TextureOverride without casting // a TextureOverride without casting