123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include "ModelInfo.h"
- using namespace Framework;
- ModelInfo::ModelInfo(const char* modelPath,
- Framework::RCArray<Framework::Text> texturePaths,
- bool transparent, float size)
- : ReferenceCounter(),
- modelPath(modelPath),
- texturePaths(texturePaths),
- transparent(transparent),
- size(size)
- {}
- void ModelInfo::writeTo(Framework::StreamWriter* zWriter) const
- {
- char len = (char)modelPath.getLength();
- zWriter->schreibe(&len, 1);
- zWriter->schreibe(modelPath.getText(), (int)len);
- short count = (short)texturePaths.getEintragAnzahl();
- zWriter->schreibe((char*)&count, 2);
- for (Text* t : texturePaths)
- {
- len = (char)t->getLength();
- zWriter->schreibe(&len, 1);
- zWriter->schreibe(t->getText(), (int)len);
- }
- zWriter->schreibe((char*)&transparent, 1);
- zWriter->schreibe((char*)&size, 4);
- }
- Framework::Text ModelInfo::getModelPath() const
- {
- return modelPath;
- }
- Framework::RCArray<Framework::Text> ModelInfo::getTexturePaths() const
- {
- return texturePaths;
- }
- bool ModelInfo::isTransparent() const
- {
- return transparent;
- }
- float ModelInfo::getSize() const
- {
- return size;
- }
- ModelInfoFactory::ModelInfoFactory()
- : TypeFactory()
- {}
- ModelInfo* ModelInfoFactory::fromJson(Framework::JSON::JSONValue* zJson) const
- {
- Framework::RCArray<Framework::Text> texturePaths;
- for (Framework::JSON::JSONValue* v :
- *zJson->asObject()->zValue("texturePaths")->asArray())
- {
- texturePaths.add(new Framework::Text(v->asString()->getString()));
- }
- return new ModelInfo(
- zJson->asObject()->zValue("modelPath")->asString()->getString(),
- texturePaths,
- zJson->asObject()->zValue("transparent")->asBool()->getBool(),
- (float)zJson->asObject()->zValue("size")->asNumber()->getNumber());
- }
- Framework::JSON::JSONValue* ModelInfoFactory::toJson(ModelInfo* zObject) const
- {
- Framework::JSON::JSONObject* obj = new Framework::JSON::JSONObject();
- Framework::JSON::JSONArray* arr = new Framework::JSON::JSONArray();
- for (Framework::Text* t : zObject->texturePaths)
- {
- arr->addValue(new Framework::JSON::JSONString(t->getText()));
- }
- obj->addValue("texturePaths", arr);
- obj->addValue(
- "modelPath", new Framework::JSON::JSONString(zObject->modelPath));
- obj->addValue(
- "transparent", new Framework::JSON::JSONBool(zObject->transparent));
- obj->addValue(
- "size", new Framework::JSON::JSONNumber(zObject->size));
- return obj;
- }
- Framework::JSON::Validator::JSONValidator*
- ModelInfoFactory::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredArray("texturePaths")
- ->addAcceptedStringInArray()
- ->finishString()
- ->finishArray()
- ->withRequiredString("modelPath")
- ->finishString()
- ->withRequiredBool("transparent")
- ->withDefault(false)
- ->finishBool()
- ->withRequiredNumber("size")
- ->whichIsGreaterThen(0)
- ->withDefault(1.0)
- ->finishNumber()
- ->finishObject();
- }
|