StatComponentParser.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "StatComponentParser.hpp"
00023 #include "sim/schema/SimSchema.hpp"
00024 #include "io/parse/ParseManager.hpp"
00025 #include "io/schema/IoSchema.hpp"
00026 #include "util/error/Log.hpp"
00027 #include "sim/stat/DictionaryEntry.hpp"
00028 #include "sim/custom/StatComponentFactory.hpp"
00029 #include "sim/script/Script.hpp"
00030 
00031 
00032 
00033 namespace se_core {
00034     const StatComponentParser parserStatComponent;
00035 
00036     StatComponentParser
00037     ::StatComponentParser()
00038             : ComponentParser(IoSchema::parser(), TYPE, SUBTYPE)
00039             , dict_(DE_COMPONENT_TYPE, TYPE, "STAT") {
00040     }
00041 
00042     
00043     StatComponentParser
00044     ::~StatComponentParser() {
00045     }
00046 
00047 
00048     ComponentFactory* StatComponentParser
00049     ::parse(InputStream& in) {
00050         StatComponentFactory* factory = new StatComponentFactory();
00051 
00052         static int dict_PROPERTY_TYPE = DE_PROPERTY_TYPE;
00053         static const DictionaryEntry deShort(dict_PROPERTY_TYPE, Property::PT_SHORT, "SHORT");
00054         static const DictionaryEntry deInt(dict_PROPERTY_TYPE, Property::PT_INT, "INT");
00055         static const DictionaryEntry deFloat(dict_PROPERTY_TYPE, Property::PT_FLOAT, "FLOAT");
00056         static const DictionaryEntry deStringList(dict_PROPERTY_TYPE, Property::PT_STRING, "STRING");
00057         static const DictionaryEntry deString(dict_PROPERTY_TYPE, Property::PT_STRING_LIST, "STRING_LIST");
00058         static const DictionaryEntry deScript(dict_PROPERTY_TYPE, Property::PT_SCRIPT, "SCRIPT");
00059         static const DictionaryEntry deAction(dict_PROPERTY_TYPE, Property::PT_ACTION, "ACTION");
00060         static const DictionaryEntry deArea(dict_PROPERTY_TYPE, Property::PT_AREA, "AREA");
00061 
00062         enum UserDefined { pt_DICT = Property::PT_END_OF_TYPES };
00063         static const DictionaryEntry deDict(dict_PROPERTY_TYPE, pt_DICT, "DICT");
00064         int code = in.readInfoCode();
00065         Assert(code == '{');
00066 
00067         while((code = in.readInfoCode()) != '}') {
00068             switch(code) {
00069             // Abilites
00070             case 'A':
00071                 {
00072                     int speed = in.readShort();
00073                     int attack = in.readShort();
00074                     int defense = in.readShort();
00075                     int level = in.readShort();
00076                     factory->setAbilities(speed, attack, defense, level);
00077                 }
00078                 break;
00079 
00080             case 'S':
00081                 {
00082                     factory->setShouldSave(true);
00083                 }
00084                 break;
00085 
00086             case 'P':
00087                 {
00088                     int propertyType = in.readDictionaryWord(dict_PROPERTY_TYPE);
00089                     String name;
00090                     in.readString(name);
00091                     Property* p = 0;
00092                     switch(propertyType) {
00093                     case Property::PT_SHORT:
00094                         p = new Property(name.get(), (short)in.readShort());
00095                         break;
00096                     case Property::PT_INT:
00097                         p = new Property(name.get(), in.readInt());
00098                         break;
00099                     case Property::PT_FLOAT:
00100                         p = new Property(name.get(), in.readFloat());
00101                         break;
00102                     case Property::PT_STRING:
00103                         {
00104                             String* tmp = new String();
00105                             in.readString(*tmp);
00106                             p = new Property(name.get(), tmp);
00107                         }
00108                         break;
00109                     case Property::PT_STRING_LIST:
00110                         {
00111                             int c = in.readShort();
00112                             String* tmp = new String[ c ];
00113                             for(int i = 0; i < c; ++i)
00114                                 in.readString(tmp[i]);
00115                             p = new Property(name.get(), c, tmp);
00116                         }
00117                         break;
00118                     case Property::PT_ACTION:
00119                         {
00120                             String tmp;
00121                             in.readString(tmp);
00122                             p = new Property(name.get(), Action::lookup(tmp.get()));
00123                         }
00124                         break;
00125                     case Property::PT_SCRIPT:
00126                         {
00127                             String tmp;
00128                             in.readString(tmp);
00129                             p = new Property(name.get(), Script::lookup(tmp.get()));
00130                         }
00131                         break;
00132 
00133                     case pt_DICT:
00134                         {
00135                             short dict = in.readDictionaryWord(DE_DICTIONARY_TYPE);
00136                             short value = in.readDictionaryWord(dict);
00137                             p = new Property(name.get(), value);
00138                         }
00139                         break;
00140                     }
00141                     if(p) {
00142                         factory->properties().add(*p);
00143                     }
00144                 }
00145                 break;
00146             default:
00147                 LogFatal("Unsupported code '" << (char)(code) << "' in file " << in.name());
00148             }
00149         }
00150 
00151         return factory;
00152     }
00153 
00154 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo