Selaa lähdekoodia

create json validator xml files for each parsable json config ftype after initialisation

Kolja Strohm 8 kuukautta sitten
vanhempi
commit
865c67739a
3 muutettua tiedostoa jossa 30 lisäystä ja 1 poistoa
  1. 3 0
      FactoryCraft/Game.cpp
  2. 22 1
      FactoryCraft/TypeRegistry.cpp
  3. 5 0
      FactoryCraft/TypeRegistry.h

+ 3 - 0
FactoryCraft/Game.cpp

@@ -603,6 +603,9 @@ void Game::initialize()
     multiblockStructureTypes = new MultiblockStructureType*[1];
     multiblockStructureTypes[0] = new MultiblockTreeStructureType();
     multiblockStructureTypeCount = 1;
+    // save syntax info
+    Framework::DateiRemove("data/syntax");
+    typeRegistry->writeSyntaxInfo("data/syntax");
     // initialize world generator and world loader
     int seed = 0;
     int index = 0;

+ 22 - 1
FactoryCraft/TypeRegistry.cpp

@@ -1,5 +1,7 @@
 #include "TypeRegistry.h"
 
+#include <Datei.h>
+
 #include "BasicBlocks.h"
 #include "BasicItems.h"
 #include "BasicTool.h"
@@ -201,4 +203,23 @@ Dimension* TypeRegistry::createDimension(int id)
         }
     }
     return 0;
-}
+}
+
+void TypeRegistry::writeSyntaxInfo(Framework::Text folderPath) const
+{
+    for (Framework::Text* typeId : parsableTypeNames)
+    {
+        TypeFatoryRef* factory
+            = parsableTypes.z(typeId->getText(), typeId->getLength());
+        Framework::JSON::Validator::JSONValidator* validator
+            = factory->getValidator();
+        Framework::Datei syntaxFile(
+            new Framework::Text(folderPath + "/" + *typeId + ".xml"));
+        syntaxFile.erstellen();
+        Framework::Text syntaxContent = validator->zConstraints()->toString();
+        syntaxFile.open(Framework::Datei::Style::schreiben);
+        syntaxFile.schreibe(syntaxContent, syntaxContent.getLength());
+        syntaxFile.close();
+        validator->release();
+    }
+}

+ 5 - 0
FactoryCraft/TypeRegistry.h

@@ -330,6 +330,7 @@ private:
     Framework::RCArray<DimensionGeneratorFactory> dimensionGenerators;
     Framework::RCArray<DimensionFactory> dimensionFactories;
     Framework::RCTrie<TypeFatoryRef> parsableTypes;
+    Framework::RCArray<Framework::Text> parsableTypeNames;
 
 public:
     TypeRegistry();
@@ -363,6 +364,7 @@ public:
                 = new PolymorphTypeFactory<T>();
             registerType(polymorphFactory);
             typeFactoryRef = parsableTypes.z(typeId, typeId.getLength());
+            parsableTypeNames.add(new Framework::Text(typeId));
         }
         PolymorphTypeFactory<T>* polymorphFactory
             = dynamic_cast<PolymorphTypeFactory<T>*>(
@@ -392,6 +394,7 @@ public:
             [factory]() { return factory->getValidator(); },
             factory);
         parsableTypes.set(typeId, typeId.getLength(), typeFactoryRef);
+        parsableTypeNames.add(new Framework::Text(typeId));
     }
 
     template<typename T> T* fromJson(Framework::JSON::JSONValue* zJson) const
@@ -447,4 +450,6 @@ public:
         }
         return result;
     }
+
+    void writeSyntaxInfo(Framework::Text folderPath) const;
 };