Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / tools / leveldesign / georges_convert / mold_loader.cpp
blob27751fcf31da702a483d9c44283774fe6b2d6d69
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdgeorgesconvert.h"
18 #include "mold_loader.h"
19 #include "mold_elt.h"
20 #include "mold_elt_define.h"
21 #include "mold_elt_type.h"
22 #include "mold_elt_define_list.h"
23 #include "mold_elt_type_list.h"
24 #include "georges_loader.h"
26 namespace NLOLDGEORGES
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
33 CMoldLoader::CMoldLoader()
37 CMoldLoader::~CMoldLoader()
39 Clear();
42 void CMoldLoader::Clear()
44 for( std::vector< CMoldElt* >::iterator it = vpme.begin(); it != vpme.end(); ++it )
45 if( *it )
46 delete( *it );
47 vpme.clear();
48 mmold.clear();
51 void CMoldLoader::SetLoader( CLoader* const _pl )
53 nlassert( _pl );
54 pl = _pl;
57 CMoldElt* CMoldLoader::LoadMold( const CStringEx _sxfilename )
59 CStringEx sxfn = _sxfilename;
60 sxfn.purge();
61 if( sxfn.empty() )
62 return( 0 );
64 // liste?
65 bool blst = ( sxfn.find( "list<" ) != -1 );
66 if( blst )
68 unsigned int ipos = sxfn.find( ">" );
69 if( ipos < 0 )
70 return( 0 );
71 sxfn.mid( 5, ipos-5 );
74 // find extension
75 int ipos = sxfn.reverse_find('.');
76 if( ipos < 0 )
77 return( 0 );
78 CStringEx sxfileextension = sxfn.get_right( sxfn.length()-ipos-1 );
80 // Get only the filename
81 ipos = sxfn.reverse_find('\\');
82 if (ipos >= 0)
83 sxfn = sxfn.get_right (sxfn.length()-ipos-1);
85 // find if loaded
86 CMoldElt* pme;
87 CStringEx sxfullname = pl->WhereIsDfnTyp( sxfn );
88 if (sxfullname == "")
89 throw NLMISC::Exception ("Unable to find " + sxfn);
91 sxfullname.make_lower();
92 std::map< CStringEx, CMoldElt* >::iterator it;
94 // DEBUG
95 /*for (it = mmold.begin(); it != mmold.end(); ++it)
97 CMoldElt *pME = it->second;
98 CStringEx sTmp = it->first + " Name:" + pME->GetName() + " formula:" + pME->GetFormula();
99 nlwarning (sTmp.c_str());
101 // DEBUG
103 it = mmold.find( sxfullname );
104 if( it != mmold.end() )
105 if( blst )
107 if( sxfileextension == "dfn" )
108 pme = new CMoldEltDefineList( pl, dynamic_cast< CMoldEltDefine* >( it->second ) );
109 else if( sxfileextension == "typ" )
110 pme = new CMoldEltTypeList( pl, dynamic_cast< CMoldEltType* >( it->second ) );
111 else
112 return 0;
113 pme->SetName( it->second->GetName() );
114 vpme.push_back( pme );
115 return( pme );
117 else
118 return( it->second );
120 // load
121 if( sxfileextension == "dfn" )
123 pme = new CMoldEltDefine( pl );
124 vpme.push_back( pme );
125 if( blst )
127 pme = new CMoldEltDefineList( pl, dynamic_cast< CMoldEltDefine* >( pme ) );
128 vpme.push_back( pme );
131 else if( sxfileextension == "typ" )
133 pme = new CMoldEltType( pl );
134 vpme.push_back( pme );
135 if( blst )
137 pme = new CMoldEltTypeList( pl, dynamic_cast< CMoldEltType* >( pme ) );
138 vpme.push_back( pme );
141 else
142 return( 0 );
144 pme->SetName( sxfn );
145 pme->Load( sxfullname );
146 mmold.insert( std::make_pair( sxfullname, pme->GetMold() ) );
147 return( pme );
150 CMoldElt* CMoldLoader::LoadMold( const CStringEx _sxfilename, const CStringEx _sxdate )
152 return( 0 );
155 CMoldElt* CMoldLoader::Find( const CStringEx _sxfullname )
157 std::map< CStringEx, CMoldElt* >::iterator it = mmold.find( _sxfullname );
158 if( it != mmold.end() )
159 return( it->second );
160 return( 0 );