123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- #include "JsonExpression.h"
- #include "Dimension.h"
- #include "DimensionGenerator.h"
- #include "Game.h"
- JExpressionMemory::JExpressionMemory()
- : ReferenceCounter(),
- currentChunk(0)
- {}
- JExpressionMemory::~JExpressionMemory()
- {
- if (currentChunk) currentChunk->release();
- }
- void JExpressionMemory::lock()
- {
- cs.lock();
- }
- void JExpressionMemory::unlock()
- {
- cs.unlock();
- }
- float JExpressionMemory::getNoise(
- Framework::Text name, float x, float y, float z) const
- {
- Noise* currentNoise = noises.z(name, name.getLength());
- if (currentNoise)
- return (float)currentNoise->getNoise((double)x, (double)y, (double)z);
- return 0.f;
- }
- void JExpressionMemory::setNoise(Framework::Text name, Noise* noise)
- {
- noises.set(name, name.getLength(), noise);
- }
- void JExpressionMemory::setCurrentChunk(Chunk* chunk)
- {
- if (currentChunk) currentChunk->release();
- currentChunk = chunk;
- }
- float JExpressionMemory::getFloatVariable(Framework::Text name) const
- {
- return floatVariables.get(name, name.getLength());
- }
- void JExpressionMemory::setFloatVariable(Framework::Text name, float value)
- {
- floatVariables.set(name, name.getLength(), value);
- }
- bool JExpressionMemory::getBoolVariable(Framework::Text name) const
- {
- return boolVariables.get(name, name.getLength());
- }
- void JExpressionMemory::setBoolVariable(Framework::Text name, bool value)
- {
- return boolVariables.set(name, name.getLength(), value);
- }
- Chunk* JExpressionMemory::zCurrentChunk()
- {
- return currentChunk;
- }
- JFloatExpression::JFloatExpression()
- : ReferenceCounter()
- {}
- JBoolExpression::JBoolExpression()
- : ReferenceCounter()
- {}
- JVariableFloatExpression::JVariableFloatExpression()
- : JFloatExpression()
- {}
- float JVariableFloatExpression::getValue(JExpressionMemory* zMemory)
- {
- return zMemory->getFloatVariable(name);
- }
- void JVariableFloatExpression::setName(Framework::Text name)
- {
- this->name = name;
- }
- Framework::Text JVariableFloatExpression::getName() const
- {
- return name;
- }
- JVariableFloatExpressionFactory::JVariableFloatExpressionFactory()
- : SubTypeFactory()
- {}
- JVariableFloatExpression* JVariableFloatExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JVariableFloatExpression();
- }
- void JVariableFloatExpressionFactory::fromJson(
- JVariableFloatExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setName(zJson->zValue("name")->asString()->getString());
- }
- void JVariableFloatExpressionFactory::toJson(JVariableFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "name", new Framework::JSON::JSONString(zObject->getName()));
- }
- JSONObjectValidationBuilder* JVariableFloatExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("name")->finishString();
- }
- Framework::Text JVariableFloatExpressionFactory::getTypeToken() const
- {
- return "variable";
- }
- JVariableBoolExpression::JVariableBoolExpression()
- : JBoolExpression()
- {}
- bool JVariableBoolExpression::getValue(JExpressionMemory* zMemory)
- {
- return zMemory->getBoolVariable(name);
- }
- void JVariableBoolExpression::setName(Framework::Text name)
- {
- this->name = name;
- }
- Framework::Text JVariableBoolExpression::getName() const
- {
- return name;
- }
- JVariableBoolExpressionFactory::JVariableBoolExpressionFactory()
- : SubTypeFactory()
- {}
- JVariableBoolExpression* JVariableBoolExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JVariableBoolExpression();
- }
- void JVariableBoolExpressionFactory::fromJson(
- JVariableBoolExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setName(zJson->zValue("name")->asString()->getString());
- }
- void JVariableBoolExpressionFactory::toJson(JVariableBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "name", new Framework::JSON::JSONString(zObject->getName()));
- }
- JSONObjectValidationBuilder* JVariableBoolExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("name")->finishString();
- }
- Framework::Text JVariableBoolExpressionFactory::getTypeToken() const
- {
- return "variable";
- }
- JConstantFloatExpression::JConstantFloatExpression()
- : JFloatExpression(),
- value(0)
- {}
- float JConstantFloatExpression::getValue(JExpressionMemory* zMemory)
- {
- return value;
- }
- void JConstantFloatExpression::setValue(float value)
- {
- this->value = value;
- }
- float JConstantFloatExpression::getValue() const
- {
- return value;
- }
- JConstantFloatExpressionFactory::JConstantFloatExpressionFactory()
- : SubTypeFactory()
- {}
- JConstantFloatExpression* JConstantFloatExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JConstantFloatExpression();
- }
- void JConstantFloatExpressionFactory::fromJson(
- JConstantFloatExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setValue((float)zJson->zValue("value")->asNumber()->getNumber());
- }
- void JConstantFloatExpressionFactory::toJson(JConstantFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "value", new Framework::JSON::JSONNumber(zObject->getValue()));
- }
- JSONObjectValidationBuilder* JConstantFloatExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("value")->finishNumber();
- }
- Framework::Text JConstantFloatExpressionFactory::getTypeToken() const
- {
- return "constant";
- }
- JConstantBoolExpression::JConstantBoolExpression()
- : JBoolExpression()
- {}
- bool JConstantBoolExpression::getValue(JExpressionMemory* zMemory)
- {
- return value;
- }
- void JConstantBoolExpression::setValue(bool value)
- {
- this->value = value;
- }
- bool JConstantBoolExpression::getValue() const
- {
- return value;
- }
- JConstantBoolExpressionFactory::JConstantBoolExpressionFactory()
- : SubTypeFactory()
- {}
- JConstantBoolExpression* JConstantBoolExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JConstantBoolExpression();
- }
- void JConstantBoolExpressionFactory::fromJson(
- JConstantBoolExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setValue(zJson->zValue("value")->asBool()->getBool());
- }
- void JConstantBoolExpressionFactory::toJson(JConstantBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "value", new Framework::JSON::JSONBool(zObject->getValue()));
- }
- JSONObjectValidationBuilder* JConstantBoolExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredBool("value")->finishBool();
- }
- Framework::Text JConstantBoolExpressionFactory::getTypeToken() const
- {
- return "constant";
- }
- JNoiseFloatExpression::JNoiseFloatExpression()
- : JFloatExpression(),
- x(0),
- y(0),
- z(0)
- {}
- JNoiseFloatExpression::~JNoiseFloatExpression()
- {
- if (x) x->release();
- if (y) y->release();
- if (z) z->release();
- }
- float JNoiseFloatExpression::getValue(JExpressionMemory* zMemory)
- {
- return zMemory->getNoise(
- name, x->getValue(zMemory), y->getValue(zMemory), z->getValue(zMemory));
- }
- void JNoiseFloatExpression::setName(Framework::Text name)
- {
- this->name = name;
- }
- Framework::Text JNoiseFloatExpression::getName() const
- {
- return name;
- }
- void JNoiseFloatExpression::setX(JFloatExpression* x)
- {
- if (this->x) this->x->release();
- this->x = x;
- }
- JFloatExpression* JNoiseFloatExpression::zX() const
- {
- return x;
- }
- void JNoiseFloatExpression::setY(JFloatExpression* y)
- {
- if (this->y) this->y->release();
- this->y = y;
- }
- JFloatExpression* JNoiseFloatExpression::zY() const
- {
- return y;
- }
- void JNoiseFloatExpression::setZ(JFloatExpression* z)
- {
- if (this->z) this->z->release();
- this->z = z;
- }
- JFloatExpression* JNoiseFloatExpression::zZ() const
- {
- return z;
- }
- JNoiseFloatExpressionFactory::JNoiseFloatExpressionFactory()
- : SubTypeFactory()
- {}
- JNoiseFloatExpression* JNoiseFloatExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JNoiseFloatExpression();
- }
- void JNoiseFloatExpressionFactory::fromJson(
- JNoiseFloatExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setName(zJson->zValue("name")->asString()->getString());
- zResult->setX(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("x")));
- zResult->setY(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("y")));
- zResult->setZ(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("z")));
- }
- void JNoiseFloatExpressionFactory::toJson(
- JNoiseFloatExpression* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "name", new Framework::JSON::JSONString(zObject->getName()));
- zResult->addValue(
- "x", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zX()));
- zResult->addValue(
- "y", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zY()));
- zResult->addValue(
- "z", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zZ()));
- }
- JSONObjectValidationBuilder* JNoiseFloatExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("name")
- ->finishString()
- ->withRequiredAttribute("x",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->withRequiredAttribute("y",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->withRequiredAttribute("z",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>());
- }
- Framework::Text JNoiseFloatExpressionFactory::getTypeToken() const
- {
- return "noise";
- }
- JOperatorFloatExpression::JOperatorFloatExpression()
- : JFloatExpression(),
- accumulator([](float a, float b) { return 0.f; })
- {}
- float JOperatorFloatExpression::getValue(JExpressionMemory* zMemory)
- {
- bool first = 1;
- float val = 0.f;
- for (JFloatExpression* expression : values)
- {
- if (first)
- {
- first = 0;
- val = expression->getValue(zMemory);
- }
- else
- {
- val = accumulator(val, expression->getValue(zMemory));
- }
- }
- return val;
- }
- void JOperatorFloatExpression::setOperator(
- Framework::Text op, std::function<float(float a, float b)> accumulator)
- {
- this->op = op;
- this->accumulator = accumulator;
- }
- Framework::Text JOperatorFloatExpression::getOperator()
- {
- return op;
- }
- void JOperatorFloatExpression::addValue(JFloatExpression* value)
- {
- values.add(value);
- }
- const Framework::RCArray<JFloatExpression>&
- JOperatorFloatExpression::getValues() const
- {
- return values;
- }
- JOperatorFloatExpressionFactory::JOperatorFloatExpressionFactory()
- : SubTypeFactory()
- {}
- JOperatorFloatExpression* JOperatorFloatExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JOperatorFloatExpression();
- }
- void JOperatorFloatExpressionFactory::fromJson(
- JOperatorFloatExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- Framework::Text op = zJson->zValue("operator")->asString()->getString();
- if (op.istGleich("+"))
- {
- zResult->setOperator("+", [](float a, float b) { return a + b; });
- }
- else if (op.istGleich("-"))
- {
- zResult->setOperator("-", [](float a, float b) { return a - b; });
- }
- else if (op.istGleich("*"))
- {
- zResult->setOperator("*", [](float a, float b) { return a * b; });
- }
- else if (op.istGleich("/"))
- {
- zResult->setOperator("/", [](float a, float b) { return a / b; });
- }
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("values")->asArray())
- {
- zResult->addValue(
- Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(value));
- }
- }
- void JOperatorFloatExpressionFactory::toJson(JOperatorFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "operator", new Framework::JSON::JSONString(zObject->getOperator()));
- Framework::JSON::JSONArray* values = new Framework::JSON::JSONArray();
- for (JFloatExpression* expression : zObject->getValues())
- {
- values->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson<JFloatExpression>(
- expression));
- }
- zResult->addValue("values", values);
- }
- JSONObjectValidationBuilder* JOperatorFloatExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("operator")
- ->whichIsOneOf({"+", "-", "*", "/"})
- ->finishString()
- ->withRequiredArray("values")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->finishArray();
- }
- Framework::Text JOperatorFloatExpressionFactory::getTypeToken() const
- {
- return "operator";
- }
- JBoolOperatorBoolExpression::JBoolOperatorBoolExpression()
- : JBoolExpression()
- {}
- bool JBoolOperatorBoolExpression::getValue(JExpressionMemory* zMemory)
- {
- bool first = 1;
- bool val = 0;
- for (JBoolExpression* expression : values)
- {
- if (first)
- {
- first = 0;
- val = expression->getValue(zMemory);
- }
- else
- {
- val = accumulator(val, expression->getValue(zMemory));
- }
- }
- return val;
- }
- void JBoolOperatorBoolExpression::setOperator(
- Framework::Text op, std::function<float(float a, float b)> accumulator)
- {
- this->op = op;
- this->accumulator = accumulator;
- }
- Framework::Text JBoolOperatorBoolExpression::getOperator()
- {
- return op;
- }
- void JBoolOperatorBoolExpression::addValue(JBoolExpression* value)
- {
- values.add(value);
- }
- const Framework::RCArray<JBoolExpression>&
- JBoolOperatorBoolExpression::getValues() const
- {
- return values;
- }
- JBoolOperatorBoolExpressionFactory::JBoolOperatorBoolExpressionFactory()
- : SubTypeFactory()
- {}
- JBoolOperatorBoolExpression* JBoolOperatorBoolExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JBoolOperatorBoolExpression();
- }
- void JBoolOperatorBoolExpressionFactory::fromJson(
- JBoolOperatorBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* value : *zJson->zValue("values")->asArray())
- {
- zResult->addValue(
- Game::INSTANCE->zTypeRegistry()->fromJson<JBoolExpression>(value));
- }
- Framework::Text op = zJson->zValue("operator")->asString()->getString();
- if (op.istGleich("&&"))
- {
- zResult->setOperator("&&", [](bool a, bool b) { return a && b; });
- }
- else if (op.istGleich("||"))
- {
- zResult->setOperator("||", [](bool a, bool b) { return a || b; });
- }
- }
- void JBoolOperatorBoolExpressionFactory::toJson(
- JBoolOperatorBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* values = new Framework::JSON::JSONArray();
- for (JBoolExpression* expression : zObject->getValues())
- {
- values->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson<JBoolExpression>(
- expression));
- }
- zResult->addValue("values", values);
- zResult->addValue(
- "operator", new Framework::JSON::JSONString(zObject->getOperator()));
- }
- JSONObjectValidationBuilder* JBoolOperatorBoolExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("operator")
- ->whichIsOneOf({"&&", "||"})
- ->finishString()
- ->withRequiredArray("values")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<JBoolExpression>())
- ->finishArray();
- }
- Framework::Text JBoolOperatorBoolExpressionFactory::getTypeToken() const
- {
- return "operator";
- }
- JFloatOperatorBoolExpression::JFloatOperatorBoolExpression()
- : JBoolExpression()
- {}
- bool JFloatOperatorBoolExpression::getValue(JExpressionMemory* zMemory)
- {
- bool first = 1;
- bool val = 1;
- float last = 0.f;
- for (JFloatExpression* expression : values)
- {
- float current = expression->getValue(zMemory);
- if (!first) val &= accumulator(last, current);
- first = 0;
- last = current;
- }
- return val;
- }
- void JFloatOperatorBoolExpression::setOperator(
- Framework::Text op, std::function<bool(float a, float b)> accumulator)
- {
- this->op = op;
- this->accumulator = accumulator;
- }
- Framework::Text JFloatOperatorBoolExpression::getOperator()
- {
- return op;
- }
- void JFloatOperatorBoolExpression::addValue(JFloatExpression* value)
- {
- values.add(value);
- }
- const Framework::RCArray<JFloatExpression>&
- JFloatOperatorBoolExpression::getValues() const
- {
- return values;
- }
- JFloatOperatorBoolExpressionFactory::JFloatOperatorBoolExpressionFactory()
- : SubTypeFactory()
- {}
- JFloatOperatorBoolExpression* JFloatOperatorBoolExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JFloatOperatorBoolExpression();
- }
- void JFloatOperatorBoolExpressionFactory::fromJson(
- JFloatOperatorBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::Text op = zJson->zValue("operator")->asString()->getString();
- if (op.istGleich(">"))
- {
- zResult->setOperator(
- ">", [](float a, float b) { return a > b; });
- }
- else if (op.istGleich("<"))
- {
- zResult->setOperator(
- "<", [](float a, float b) { return a < b; });
- }
- else if (op.istGleich(">="))
- {
- zResult->setOperator(
- ">=", [](float a, float b) { return a >= b; });
- }
- else if (op.istGleich("<="))
- {
- zResult->setOperator(
- "<=", [](float a, float b) { return a <= b; });
- }
- else if (op.istGleich("=="))
- {
- zResult->setOperator(
- "==", [](float a, float b) { return a == b; });
- }
- else if (op.istGleich("!="))
- {
- zResult->setOperator(
- "!=", [](float a, float b) { return a != b; });
- }
- else if (op.istGleich(">i"))
- {
- zResult->setOperator(
- ">i", [](float a, float b) { return (int)a > (int)b; });
- }
- else if (op.istGleich("<i"))
- {
- zResult->setOperator(
- "<i", [](float a, float b) { return (int)a < (int)b; });
- }
- else if (op.istGleich(">=i"))
- {
- zResult->setOperator(
- ">=i", [](float a, float b) { return (int)a >= (int)b; });
- }
- else if (op.istGleich("<=i"))
- {
- zResult->setOperator(
- "<=i", [](float a, float b) { return (int)a <= (int)b; });
- }
- else if (op.istGleich("==i"))
- {
- zResult->setOperator(
- "==i", [](float a, float b) { return (int)a == (int)b; });
- }
- else if (op.istGleich("!=i"))
- {
- zResult->setOperator(
- "!=i", [](float a, float b) { return (int)a != (int)b; });
- }
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("values")->asArray())
- {
- zResult->addValue(
- Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(value));
- }
- }
- void JFloatOperatorBoolExpressionFactory::toJson(
- JFloatOperatorBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "operator", new Framework::JSON::JSONString(zObject->getOperator()));
- Framework::JSON::JSONArray* values = new Framework::JSON::JSONArray();
- for (JFloatExpression* expression : zObject->getValues())
- {
- values->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson<JFloatExpression>(
- expression));
- }
- zResult->addValue("values", values);
- }
- JSONObjectValidationBuilder*
- JFloatOperatorBoolExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("operator")
- ->whichIsOneOf({">",
- "<",
- ">=",
- "<=",
- "==",
- "!=",
- "<i",
- ">i",
- ">=i",
- "<=i",
- "==i",
- "!=i"})
- ->finishString()
- ->withRequiredArray("values")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->finishArray();
- }
- Framework::Text JFloatOperatorBoolExpressionFactory::getTypeToken() const
- {
- return "comparsion";
- }
- JBlockTypeBoolExpression::JBlockTypeBoolExpression()
- : JBoolExpression(),
- typeId(0),
- x(0),
- y(0),
- z(0)
- {}
- JBlockTypeBoolExpression ::~JBlockTypeBoolExpression()
- {
- if (x) x->release();
- if (y) y->release();
- if (z) z->release();
- }
- bool JBlockTypeBoolExpression::getValue(JExpressionMemory* zMemory)
- {
- int x = (int)(round(this->x->getValue(zMemory)));
- int y = (int)(round(this->y->getValue(zMemory)));
- int z = (int)(round(this->z->getValue(zMemory)));
- if (z < 0 || z >= WORLD_HEIGHT || !zMemory->zCurrentChunk()
- || Game::getChunkCenter(x, y) != zMemory->zCurrentChunk()->getCenter())
- {
- return 0;
- }
- return zMemory->zCurrentChunk()->getBlockTypeAt(
- Dimension::chunkCoordinates({x, y, z}))
- == typeId;
- }
- void JBlockTypeBoolExpression::setTypeId(int typeId)
- {
- this->typeId = typeId;
- }
- int JBlockTypeBoolExpression::getTypeId() const
- {
- return typeId;
- }
- void JBlockTypeBoolExpression::setX(JFloatExpression* x)
- {
- if (this->x) this->x->release();
- this->x = x;
- }
- JFloatExpression* JBlockTypeBoolExpression::zX() const
- {
- return x;
- }
- void JBlockTypeBoolExpression::setY(JFloatExpression* y)
- {
- if (this->y) this->y->release();
- this->y = y;
- }
- JFloatExpression* JBlockTypeBoolExpression::zY() const
- {
- return y;
- }
- void JBlockTypeBoolExpression::setZ(JFloatExpression* z)
- {
- if (this->z) this->z->release();
- this->z = z;
- }
- JFloatExpression* JBlockTypeBoolExpression::zZ() const
- {
- return z;
- }
- JBlockTypeBoolExpressionFactory::JBlockTypeBoolExpressionFactory()
- : SubTypeFactory()
- {}
- JBlockTypeBoolExpression* JBlockTypeBoolExpressionFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new JBlockTypeBoolExpression();
- }
- void JBlockTypeBoolExpressionFactory::fromJson(
- JBlockTypeBoolExpression* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setTypeId(Game::INSTANCE->getBlockTypeId(
- zJson->zValue("blockType")->asString()->getString()));
- zResult->setX(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("x")));
- zResult->setY(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("y")));
- zResult->setZ(Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
- zJson->zValue("z")));
- }
- void JBlockTypeBoolExpressionFactory::toJson(JBlockTypeBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("blockType",
- new Framework::JSON::JSONString(
- Game::INSTANCE->zBlockType(zObject->getTypeId())->getName()));
- zResult->addValue(
- "x", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zX()));
- zResult->addValue(
- "y", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zY()));
- zResult->addValue(
- "z", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zZ()));
- }
- JSONObjectValidationBuilder* JBlockTypeBoolExpressionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- Framework::RCArray<Framework::Text> blockTypeNames;
- for (int i = 0; i < Game::INSTANCE->getBlockTypeCount(); i++)
- {
- if (Game::INSTANCE->zBlockType(i))
- {
- blockTypeNames.add(
- new Framework::Text(Game::INSTANCE->zBlockType(i)->getName()));
- }
- }
- return builder->withRequiredString("blockType")
- ->whichIsOneOf(blockTypeNames)
- ->finishString()
- ->withRequiredAttribute("x",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->withRequiredAttribute("y",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>())
- ->withRequiredAttribute("z",
- Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>());
- }
- Framework::Text JBlockTypeBoolExpressionFactory::getTypeToken() const
- {
- return "blockType";
- }
|