| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include "UICraftingGrid.h"
- #include "UIReference.h"
- UICraftingGrid::UICraftingGrid()
- : UIElement(),
- rowSize(0),
- colSize(0),
- numOutputSlots(0),
- target(0)
- {}
- UICraftingGrid::~UICraftingGrid()
- {
- if (target)
- {
- target->release();
- }
- }
- void UICraftingGrid::setRowSize(int rowSize)
- {
- this->rowSize = rowSize;
- }
- int UICraftingGrid::getRowSize() const
- {
- return rowSize;
- }
- void UICraftingGrid::setColSize(int colSize)
- {
- this->colSize = colSize;
- }
- int UICraftingGrid::getColSize() const
- {
- return colSize;
- }
- void UICraftingGrid::setNumOutputSlots(int numOutputSlots)
- {
- this->numOutputSlots = numOutputSlots;
- }
- int UICraftingGrid::getNumOutputSlots() const
- {
- return numOutputSlots;
- }
- void UICraftingGrid::setTarget(UIReference* target)
- {
- if (this->target)
- {
- this->target->release();
- }
- this->target = target;
- }
- UIReference* UICraftingGrid::zTarget() const
- {
- return target;
- }
- Framework::XML::Element* UICraftingGrid::toUIML(
- Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
- {
- Framework::XML::Element* result = UIElement::toUIML(zTarget, zActor);
- result->setName("craftingGrid");
- result->setAttribute("rowSize", rowSize);
- result->setAttribute("colSize", colSize);
- result->setAttribute("numOutputSlots", numOutputSlots);
- if (target)
- {
- result->setAttribute("target", target->getReferenceId(zTarget, zActor));
- }
- return result;
- }
- UICraftingGridElementFactory::UICraftingGridElementFactory()
- : UIElementFactory<UICraftingGrid>()
- {}
- JSONObjectValidationBuilder* UICraftingGridElementFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return UIElementFactory<UICraftingGrid>::addToValidator(builder)
- ->withRequiredNumber("rowSize")
- ->whichIsGreaterThen(0)
- ->finishNumber()
- ->withRequiredNumber("colSize")
- ->whichIsGreaterThen(0)
- ->finishNumber()
- ->withRequiredNumber("numOutputSlots")
- ->whichIsGreaterThen(0)
- ->finishNumber()
- ->withRequiredAttribute("target",
- Game::INSTANCE->zTypeRegistry()->getValidator<UIReference>());
- }
- UICraftingGrid* UICraftingGridElementFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- UICraftingGrid* result = UIElementFactory<UICraftingGrid>::fromJson(zJson);
- result->setRowSize((int)zJson->zValue("rowSize")->asNumber()->getNumber());
- result->setColSize((int)zJson->zValue("colSize")->asNumber()->getNumber());
- result->setNumOutputSlots(
- (int)zJson->zValue("numOutputSlots")->asNumber()->getNumber());
- result->setTarget(Game::INSTANCE->zTypeRegistry()->fromJson<UIReference>(
- zJson->zValue("target")->asObject()));
- return result;
- }
- Framework::JSON::JSONObject* UICraftingGridElementFactory::toJsonObject(
- UICraftingGrid* zObject) const
- {
- Framework::JSON::JSONObject* result
- = UIElementFactory<UICraftingGrid>::toJsonObject(zObject);
- result->addValue(
- "rowSize", new Framework::JSON::JSONNumber(zObject->getRowSize()));
- result->addValue(
- "colSize", new Framework::JSON::JSONNumber(zObject->getColSize()));
- result->addValue("numOutputSlots",
- new Framework::JSON::JSONNumber(zObject->getNumOutputSlots()));
- result->addValue("target",
- Game::INSTANCE->zTypeRegistry()->toJson<UIReference>(
- zObject->zTarget()));
- return result;
- }
- UICraftingGrid* UICraftingGridElementFactory::createElement(
- Framework::JSON::JSONObject* zJson) const
- {
- return new UICraftingGrid();
- }
- const char* UICraftingGridElementFactory::getTypeToken() const
- {
- return "craftingGrid";
- }
|