#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 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() {} JSONObjectValidationBuilder* UICraftingGridElementFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return UIElementFactory::addToValidator(builder) ->withRequiredNumber("rowSize") ->whichIsGreaterThen(0) ->finishNumber() ->withRequiredNumber("colSize") ->whichIsGreaterThen(0) ->finishNumber() ->withRequiredNumber("numOutputSlots") ->whichIsGreaterThen(0) ->finishNumber() ->withRequiredAttribute("target", Game::INSTANCE->zTypeRegistry()->getValidator()); } UICraftingGrid* UICraftingGridElementFactory::fromJson( Framework::JSON::JSONObject* zJson) const { UICraftingGrid* result = UIElementFactory::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( zJson->zValue("target")->asObject())); return result; } Framework::JSON::JSONObject* UICraftingGridElementFactory::toJsonObject( UICraftingGrid* zObject) const { Framework::JSON::JSONObject* result = UIElementFactory::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( zObject->zTarget())); return result; } UICraftingGrid* UICraftingGridElementFactory::createElement( Framework::JSON::JSONObject* zJson) const { return new UICraftingGrid(); } const char* UICraftingGridElementFactory::getTypeToken() const { return "craftingGrid"; }