|
|
@@ -71,12 +71,13 @@ void ItemSlot::addItems(ItemStack* zStack, Direction dir)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ItemSlot::update() {
|
|
|
+void ItemSlot::update()
|
|
|
+{
|
|
|
if (items && items->getSize() == 0)
|
|
|
{
|
|
|
- items->release();
|
|
|
- items = 0;
|
|
|
- }
|
|
|
+ items->release();
|
|
|
+ items = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int ItemSlot::numberOfAddableItems(const ItemStack* zStack, Direction dir) const
|
|
|
@@ -140,4 +141,177 @@ const Framework::Text& ItemSlot::getName() const
|
|
|
int ItemSlot::getId() const
|
|
|
{
|
|
|
return id;
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+ItemSlotFactory::ItemSlotFactory()
|
|
|
+ : ObjectTypeFactory()
|
|
|
+{}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder* ItemSlotFactory::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONArray* defaultSides = new Framework::JSON::JSONArray();
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("TOP"));
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("BOTTOM"));
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("NORTH"));
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("EAST"));
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("SOUTH"));
|
|
|
+ defaultSides->addValue(new Framework::JSON::JSONString("WEST"));
|
|
|
+ return builder->withRequiredString("category")
|
|
|
+ ->withDefault("Inventory")
|
|
|
+ ->finishString()
|
|
|
+ ->withRequiredNumber("maxSize")
|
|
|
+ ->withDefault(50.0)
|
|
|
+ ->finishNumber()
|
|
|
+ ->withRequiredNumber("pullPriority")
|
|
|
+ ->whichIsGreaterThen(0.0)
|
|
|
+ ->withDefault(1.0)
|
|
|
+ ->finishNumber()
|
|
|
+ ->withRequiredNumber("pushPriority")
|
|
|
+ ->whichIsGreaterThen(0.0)
|
|
|
+ ->withDefault(1.0)
|
|
|
+ ->finishNumber()
|
|
|
+ ->withRequiredArray("allowedPullSides")
|
|
|
+ ->withDefault(
|
|
|
+ dynamic_cast<Framework::JSON::JSONArray*>(defaultSides->getThis()))
|
|
|
+ ->addAcceptedStringInArray()
|
|
|
+ ->whichIsOneOf({"TOP", "BOTTOM", "NORTH", "EAST", "SOUTH", "WEST"})
|
|
|
+ ->finishString()
|
|
|
+ ->finishArray()
|
|
|
+ ->withRequiredArray("allowedPushSides")
|
|
|
+ ->withDefault(defaultSides)
|
|
|
+ ->addAcceptedStringInArray()
|
|
|
+ ->whichIsOneOf({"TOP", "BOTTOM", "NORTH", "EAST", "SOUTH", "WEST"})
|
|
|
+ ->finishString()
|
|
|
+ ->finishArray()
|
|
|
+ ->withRequiredBool("allowHigherStackSize")
|
|
|
+ ->withDefault(false)
|
|
|
+ ->finishBool();
|
|
|
+}
|
|
|
+
|
|
|
+ItemSlot* ItemSlotFactory::fromJson(Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ Framework::Text category
|
|
|
+ = zJson->zValue("category")->asString()->getString();
|
|
|
+ int maxSize = (int)zJson->zValue("maxSize")->asNumber()->getNumber();
|
|
|
+ int pullPriority
|
|
|
+ = (int)zJson->zValue("pullPriority")->asNumber()->getNumber();
|
|
|
+ int pushPriority
|
|
|
+ = (int)zJson->zValue("pushPriority")->asNumber()->getNumber();
|
|
|
+ int allowedPullSides = 0;
|
|
|
+ int allowedPushSides = 0;
|
|
|
+ for (Framework::JSON::JSONValue* side :
|
|
|
+ *zJson->zValue("allowedPullSides")->asArray())
|
|
|
+ {
|
|
|
+ Framework::Text sideText = side->asString()->getString();
|
|
|
+ if (sideText.istGleich("TOP"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= TOP;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("BOTTOM"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= BOTTOM;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("NORTH"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= NORTH;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("EAST"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= EAST;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("SOUTH"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= SOUTH;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("WEST"))
|
|
|
+ {
|
|
|
+ allowedPullSides |= WEST;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Framework::JSON::JSONValue* side :
|
|
|
+ *zJson->zValue("allowedPushSides")->asArray())
|
|
|
+ {
|
|
|
+ Framework::Text sideText = side->asString()->getString();
|
|
|
+ if (sideText.istGleich("TOP"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= TOP;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("BOTTOM"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= BOTTOM;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("NORTH"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= NORTH;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("EAST"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= EAST;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("SOUTH"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= SOUTH;
|
|
|
+ }
|
|
|
+ else if (sideText.istGleich("WEST"))
|
|
|
+ {
|
|
|
+ allowedPushSides |= WEST;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bool allowHigherStackSize
|
|
|
+ = zJson->zValue("allowHigherStackSize")->asBool()->getBool();
|
|
|
+ return new ItemSlot(category,
|
|
|
+ maxSize,
|
|
|
+ pullPriority,
|
|
|
+ pushPriority,
|
|
|
+ allowedPullSides,
|
|
|
+ allowedPushSides,
|
|
|
+ allowHigherStackSize);
|
|
|
+}
|
|
|
+
|
|
|
+Framework::JSON::JSONObject* ItemSlotFactory::toJsonObject(
|
|
|
+ ItemSlot* zObject) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
|
|
|
+ result->addValue(
|
|
|
+ "category", new Framework::JSON::JSONString(zObject->getName()));
|
|
|
+ result->addValue(
|
|
|
+ "maxSize", new Framework::JSON::JSONNumber((double)zObject->maxSize));
|
|
|
+ result->addValue("pullPriority",
|
|
|
+ new Framework::JSON::JSONNumber((double)zObject->getPullPriority()));
|
|
|
+ result->addValue("pushPriority",
|
|
|
+ new Framework::JSON::JSONNumber((double)zObject->getPushPriority()));
|
|
|
+ Framework::JSON::JSONArray* allowedPullSides
|
|
|
+ = new Framework::JSON::JSONArray();
|
|
|
+ if (zObject->allowedPullSide & TOP)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("TOP"));
|
|
|
+ if (zObject->allowedPullSide & BOTTOM)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("BOTTOM"));
|
|
|
+ if (zObject->allowedPullSide & NORTH)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("NORTH"));
|
|
|
+ if (zObject->allowedPullSide & EAST)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("EAST"));
|
|
|
+ if (zObject->allowedPullSide & SOUTH)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("SOUTH"));
|
|
|
+ if (zObject->allowedPullSide & WEST)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("WEST"));
|
|
|
+ result->addValue("allowedPullSides", allowedPullSides);
|
|
|
+ Framework::JSON::JSONArray* allowedPushSides
|
|
|
+ = new Framework::JSON::JSONArray();
|
|
|
+ if (zObject->allowedPushSides & TOP)
|
|
|
+ allowedPushSides->addValue(new Framework::JSON::JSONString("TOP"));
|
|
|
+ if (zObject->allowedPushSides & BOTTOM)
|
|
|
+ allowedPullSides->addValue(new Framework::JSON::JSONString("BOTTOM"));
|
|
|
+ if (zObject->allowedPushSides & NORTH)
|
|
|
+ allowedPushSides->addValue(new Framework::JSON::JSONString("NORTH"));
|
|
|
+ if (zObject->allowedPushSides & EAST)
|
|
|
+ allowedPushSides->addValue(new Framework::JSON::JSONString("EAST"));
|
|
|
+ if (zObject->allowedPushSides & SOUTH)
|
|
|
+ allowedPushSides->addValue(new Framework::JSON::JSONString("SOUTH"));
|
|
|
+ if (zObject->allowedPushSides & WEST)
|
|
|
+ allowedPushSides->addValue(new Framework::JSON::JSONString("WEST"));
|
|
|
+ result->addValue("allowedPushSides", allowedPushSides);
|
|
|
+ result->addValue("allowHigherStackSize",
|
|
|
+ new Framework::JSON::JSONBool(zObject->allowHigherStackSize));
|
|
|
+ return result;
|
|
|
+}
|