@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
33
33
#include " exceptions.h"
34
34
#include " debug.h"
35
35
#include " gamedef.h"
36
+ #include < fstream> // Used in applyTextureOverrides()
36
37
37
38
/*
38
39
NodeBox
@@ -397,6 +398,7 @@ class CNodeDefManager: public IWritableNodeDefManager {
397
398
virtual content_t set (const std::string &name, const ContentFeatures &def);
398
399
virtual content_t allocateDummy (const std::string &name);
399
400
virtual void updateAliases (IItemDefManager *idef);
401
+ virtual void applyTextureOverrides (const std::string &override_filepath);
400
402
virtual void updateTextures (IGameDef *gamedef,
401
403
void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
402
404
void *progress_cbk_args);
@@ -670,7 +672,7 @@ content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &d
670
672
j = m_group_to_items.find (group_name);
671
673
if (j == m_group_to_items.end ()) {
672
674
m_group_to_items[group_name].push_back (
673
- std::make_pair (id, i->second ));
675
+ std::make_pair (id, i->second ));
674
676
} else {
675
677
GroupItems &items = j->second ;
676
678
items.push_back (std::make_pair (id, i->second ));
@@ -700,7 +702,66 @@ void CNodeDefManager::updateAliases(IItemDefManager *idef)
700
702
content_t id;
701
703
if (m_name_id_mapping.getId (convert_to, id)) {
702
704
m_name_id_mapping_with_aliases.insert (
703
- std::make_pair (name, id));
705
+ std::make_pair (name, id));
706
+ }
707
+ }
708
+ }
709
+
710
+ void CNodeDefManager::applyTextureOverrides (const std::string &override_filepath)
711
+ {
712
+ infostream << " CNodeDefManager::applyTextureOverrides(): Applying "
713
+ " overrides to textures from " << override_filepath << std::endl;
714
+
715
+ std::ifstream infile (override_filepath.c_str ());
716
+ std::string line;
717
+ int line_c = 0 ;
718
+ while (std::getline (infile, line)) {
719
+ line_c++;
720
+ if (trim (line) == " " )
721
+ continue ;
722
+ std::vector<std::string> splitted = str_split (line, ' ' );
723
+ if (splitted.size () != 3 ) {
724
+ errorstream << override_filepath
725
+ << " :" << line_c << " Could not apply texture override \" "
726
+ << line << " \" : Syntax error" << std::endl;
727
+ continue ;
728
+ }
729
+
730
+ content_t id;
731
+ if (!getId (splitted[0 ], id)) {
732
+ errorstream << override_filepath
733
+ << " :" << line_c << " Could not apply texture override \" "
734
+ << line << " \" : Unknown node \" "
735
+ << splitted[0 ] << " \" " << std::endl;
736
+ continue ;
737
+ }
738
+
739
+ ContentFeatures &nodedef = m_content_features[id];
740
+
741
+ if (splitted[1 ] == " top" )
742
+ nodedef.tiledef [0 ].name = splitted[2 ];
743
+ else if (splitted[1 ] == " bottom" )
744
+ nodedef.tiledef [1 ].name = splitted[2 ];
745
+ else if (splitted[1 ] == " right" )
746
+ nodedef.tiledef [2 ].name = splitted[2 ];
747
+ else if (splitted[1 ] == " left" )
748
+ nodedef.tiledef [3 ].name = splitted[2 ];
749
+ else if (splitted[1 ] == " back" )
750
+ nodedef.tiledef [4 ].name = splitted[2 ];
751
+ else if (splitted[1 ] == " front" )
752
+ nodedef.tiledef [5 ].name = splitted[2 ];
753
+ else if (splitted[1 ] == " all" || splitted[1 ] == " *" )
754
+ for (int i = 0 ; i < 6 ; i++)
755
+ nodedef.tiledef [i].name = splitted[2 ];
756
+ else if (splitted[1 ] == " sides" )
757
+ for (int i = 2 ; i < 6 ; i++)
758
+ nodedef.tiledef [i].name = splitted[2 ];
759
+ else {
760
+ errorstream << override_filepath
761
+ << " :" << line_c << " Could not apply texture override \" "
762
+ << line << " \" : Unknown node side \" "
763
+ << splitted[1 ] << " \" " << std::endl;
764
+ continue ;
704
765
}
705
766
}
706
767
}