Browse Source

fix errors in recipie lookup menue uiml

Kolja Strohm 1 year ago
parent
commit
54e3efe672

+ 2 - 1
FactoryCraft/BlockType.h

@@ -41,8 +41,9 @@ public:
     static const int WHEAT_SEED = 24;
     static const int WHEAT = 25;
     static const int WATER = 26;
+    static const int CRAFTING_TABLE = 27;
 
-    static const int MAX_VALUE = 26;
+    static const int MAX_VALUE = 27;
 };
 
 class BlockType : public virtual Framework::ReferenceCounter

+ 1 - 0
FactoryCraft/Chunk.cpp

@@ -838,6 +838,7 @@ void Chunk::removeUnusedBlocks()
             if (!visible)
             {
                 putBlockAt({x, y, z}, 0);
+                putBlockTypeAt({x, y, z}, 0);
             }
         }
     }

+ 1 - 2
FactoryCraft/CraftingStorage.cpp

@@ -110,8 +110,7 @@ bool BasicShapedCrafter::isAllAvailable(Framework::RCArray<ItemFilter>& filters,
                         = craftingInput.get((h + y) * this->width + (x + w));
                     const Item* item = 0;
                     if (s && s->zStack()
-                        && s->zStack()->getSize() >= inputAmount.get(
-                               (h + y) * this->width + (x + w)))
+                        && s->zStack()->getSize() >= inputAmount.get(h * width + w))
                         item = s->zStack()->zItem();
                     wrong |= (item && !f) || (!item && f);
                     wrong |= item && f && !f->matchItem(item);

+ 5 - 1
FactoryCraft/Game.cpp

@@ -220,7 +220,10 @@ void GameClient::sendResponse(NetworkMessage* response)
                       << zPlayer->getName() << " is to slow.\n";
             ZeitMesser m;
             m.messungStart();
-            emptyForegroundQueueSync.wait();
+            while (foregroundQueue.getEintragAnzahl() > 0)
+            {
+                emptyForegroundQueueSync.wait(100);
+            }
             m.messungEnde();
             std::cout << "WARNING: Game resumed after " << m.getSekunden()
                       << " seconds.\n";
@@ -465,6 +468,7 @@ void Game::thread()
     for (Dimension* dim : *dimensions)
         dim->requestStopAndWait();
     std::cout << "Game thread exited\n";
+    getThis();
 }
 
 void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)

+ 1 - 0
FactoryCraft/Game.h

@@ -135,5 +135,6 @@ public:
     TickOrganizer* zTickOrganizer() const;
 
     static Game* INSTANCE;
+    static Critical INSTANCE_CS;
     static void initialize(Framework::Text name, Framework::Text worldsDir);
 };

+ 5 - 38
FactoryCraft/ItemFilter.cpp

@@ -53,21 +53,16 @@ bool CombinedItemFilter::matchTargetSlot(ItemSlot* zSlot) const
     return op(filterA->matchTargetSlot(zSlot), filterB->matchTargetSlot(zSlot));
 }
 
-Framework::Text CombinedItemFilter::getImageUIML() const
-{
-    return filterA->getImageUIML() + filterB->getImageUIML();
-}
-
 Framework::Text CombinedItemFilter::getLogicUIML() const
 {
     Framework::Text result = "<operator result_0_0=\"";
-    result += op(0, 0);
+    result += (int)op(0, 0);
     result += "\" result_0_1=\"";
-    result += op(0, 1);
+    result += (int)op(0, 1);
     result += "\" result_1_0=\"";
-    result += op(1, 0);
+    result += (int)op(1, 0);
     result += "\" result_1_1=\"";
-    result += op(1, 1);
+    result += (int)op(1, 1);
     result += ">";
     result += filterA->getLogicUIML();
     result += filterB->getLogicUIML();
@@ -85,11 +80,6 @@ bool AnyItemFilter::matchItem(const Item* zItem) const
     return true;
 }
 
-Framework::Text AnyItemFilter::getImageUIML() const
-{
-    return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
-}
-
 Framework::Text AnyItemFilter::getLogicUIML() const
 {
     return "<anyItem/>";
@@ -105,18 +95,10 @@ bool TypeItemFilter::matchItem(const Item* zItem) const
     return zItem->zItemType() == zType;
 }
 
-Framework::Text TypeItemFilter::getImageUIML() const
-{
-    Framework::Text result = "<img itemType=\"";
-    result += zType->getId();
-    result += "\"/>";
-    return result;
-}
-
 Framework::Text TypeItemFilter::getLogicUIML() const
 {
     Framework::Text result = "<attribute name=\"Type\" operator=\"=\" value=\"";
-    result += zType->getName();
+    result += zType->getId();
     result += "\"/>";
     return result;
 }
@@ -137,11 +119,6 @@ bool SpecificSlotFilter::matchTargetSlot(ItemSlot* zSlot) const
     return targetSlotId == zSlot->getId();
 }
 
-Framework::Text SpecificSlotFilter::getImageUIML() const
-{
-    return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
-}
-
 Framework::Text SpecificSlotFilter::getLogicUIML() const
 {
     return "<anyItem/>";
@@ -170,11 +147,6 @@ bool SourceSlotBlacklistFilter::matchTargetSlot(ItemSlot* zSlot) const
     return 1;
 }
 
-Framework::Text SourceSlotBlacklistFilter::getImageUIML() const
-{
-    return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
-}
-
 Framework::Text SourceSlotBlacklistFilter::getLogicUIML() const
 {
     return "<anyItem/>";
@@ -203,11 +175,6 @@ bool TargetSlotBlacklistFilter::matchTargetSlot(ItemSlot* zSlot) const
     return 1;
 }
 
-Framework::Text TargetSlotBlacklistFilter::getImageUIML() const
-{
-    return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
-}
-
 Framework::Text TargetSlotBlacklistFilter::getLogicUIML() const
 {
     return "<anyItem/>";

+ 0 - 7
FactoryCraft/ItemFilter.h

@@ -15,7 +15,6 @@ public:
     virtual bool matchItem(const Item* zItem) const;
     virtual bool matchSourceSlot(ItemSlot* zSlot) const;
     virtual bool matchTargetSlot(ItemSlot* zSlot) const;
-    virtual Framework::Text getImageUIML() const = 0;
     virtual Framework::Text getLogicUIML() const = 0;
 };
 
@@ -34,7 +33,6 @@ public:
     bool matchItem(const Item* zItem) const override;
     bool matchSourceSlot(ItemSlot* zSlot) const override;
     bool matchTargetSlot(ItemSlot* zSlot) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };
 
@@ -43,7 +41,6 @@ class AnyItemFilter : public ItemFilter
 public:
     AnyItemFilter();
     bool matchItem(const Item* zItem) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };
 
@@ -55,7 +52,6 @@ private:
 public:
     TypeItemFilter(const ItemType* zType);
     bool matchItem(const Item* zItem) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };
 
@@ -69,7 +65,6 @@ public:
     SpecificSlotFilter(int sourceSlotId, int targetSlotId);
     bool matchSourceSlot(ItemSlot* zSlot) const override;
     bool matchTargetSlot(ItemSlot* zSlot) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };
 
@@ -83,7 +78,6 @@ public:
     void addBlackListSlotId(int id);
     bool matchSourceSlot(ItemSlot* zSlot) const override;
     bool matchTargetSlot(ItemSlot* zSlot) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };
 
@@ -97,6 +91,5 @@ public:
     void addBlackListSlotId(int id);
     bool matchSourceSlot(ItemSlot* zSlot) const override;
     bool matchTargetSlot(ItemSlot* zSlot) const override;
-    Framework::Text getImageUIML() const override;
     Framework::Text getLogicUIML() const override;
 };

+ 2 - 1
FactoryCraft/ModelInfo.cpp

@@ -13,7 +13,8 @@ ModelInfo::ModelInfo(
 
 ModelInfo::ModelInfo(
     const char* modelPath, std::initializer_list<const char*> texturePaths)
-    : modelPath(modelPath)
+    : modelPath(modelPath),
+      transparent(0)
 {
     for (const char* texturPath : texturePaths)
         this->texturePaths.add(new Text(texturPath));

+ 1 - 1
FactoryCraft/NetworkMessage.h

@@ -21,7 +21,7 @@ private:
 
 public:
     NetworkMessage();
-    ~NetworkMessage();
+    virtual ~NetworkMessage();
 
     void addressChunck(const Chunk* zChunk);
     void addressEntity(const Entity* zEntity);

+ 22 - 16
FactoryCraft/Recipie.cpp

@@ -86,14 +86,17 @@ Framework::Text UnshapedRecipie::getRecipieUIML()
     {
         result += "<ingredient amount=\"";
         result += inputAmount.get(i);
-        result += "\"><images>";
-        result += filters.z(i)->getImageUIML();
-        result += "</images><logic>";
-        result += filters.z(i)->getLogicUIML();
-        result += "</logic></ingredient>";
-        // todo: add modifiers
+        result += "\">";
+        if (filters.z(i))
+        {
+            result += "<logic>";
+            result += filters.z(i)->getLogicUIML();
+            result += "</logic>";
+        }
+        result += "</ingredient>";
+        // TODO: add modifiers
     }
-    result += "</ingredient><outputs>";
+    result += "</ingredients><outputs>";
     for (int i = 0; i < outputs.getEintragAnzahl(); i++)
     {
         result += "<output amount=\"";
@@ -112,7 +115,7 @@ Framework::Text UnshapedRecipie::getRecipieUIML()
         result += outputs.z(i)->getTooltipUIML();
         result += "</output>";
     }
-    result += "</output></recipie>";
+    result += "</outputs></recipie>";
     return result;
 }
 
@@ -176,14 +179,17 @@ Framework::Text ShapedRecipie::getRecipieUIML()
     {
         result += "<ingredient amount=\"";
         result += inputAmount.get(i);
-        result += "\"><images>";
-        result += filters.z(i)->getImageUIML();
-        result += "</images><logic>";
-        result += filters.z(i)->getLogicUIML();
-        result += "</logic></ingredient>";
-        // todo: add modifiers
+        result += "\">";
+        if (filters.z(i))
+        {
+            result += "<logic>";
+            result += filters.z(i)->getLogicUIML();
+            result += "</logic>";
+        }
+        result += "</ingredient>";
+        // TODO: add modifiers
     }
-    result += "</ingredient><outputs>";
+    result += "</ingredients><outputs>";
     for (int i = 0; i < outputs.getEintragAnzahl(); i++)
     {
         result += "<output amount=\"";
@@ -202,6 +208,6 @@ Framework::Text ShapedRecipie::getRecipieUIML()
         result += outputs.z(i)->getTooltipUIML();
         result += "</output>";
     }
-    result += "</output></recipie>";
+    result += "</outputs></recipie>";
     return result;
 }

+ 1 - 1
FactoryCraft/RecipieList.cpp

@@ -27,7 +27,7 @@ const Framework::Text& RecipieList::getName() const
 void RecipieList::findRecipies(
     ItemType* zTargetType, Framework::RCArray<Recipie>& recipies)
 {
-    for (Recipie* recipie : recipies)
+    for (Recipie* recipie : this->recipies)
     {
         if (recipie->createsOutput(zTargetType))
         {

+ 9 - 2
FactoryCraft/RecipieLoader.cpp

@@ -183,7 +183,9 @@ void RecipieLoader::registerRecipieList(const char* name)
 
 Framework::Text RecipieLoader::getCrafingUIML(ItemType* zTargetType)
 {
-    Framework::Text result = "<craftingRecipies>";
+    Framework::Text result = "<dialog id=\"crafting_";
+    result += zTargetType->getId();
+    result += "\"><craftingRecipies>";
     for (RecipieList* list : lists)
     {
         Framework::RCArray<Recipie> recipies;
@@ -192,6 +194,11 @@ Framework::Text RecipieLoader::getCrafingUIML(ItemType* zTargetType)
         {
             result += "<craftingRecipieGroup name=\"";
             result += list->getName();
+            if (list->getName().istGleich("inventory"))
+            {
+                result += "\" itemIcon=\"";
+                result += ItemTypeEnum::CRAFTING_TABLE;
+            }
             result += "\">";
             for (Recipie* recipie : recipies)
             {
@@ -200,7 +207,7 @@ Framework::Text RecipieLoader::getCrafingUIML(ItemType* zTargetType)
             result += "</craftingRecipieGroup>";
         }
     }
-    result += "</craftingRecipies>";
+    result += "</craftingRecipies></dialog>";
     return result;
 }
 

+ 2 - 0
FactoryCraft/Start.cpp

@@ -106,6 +106,8 @@ int main()
     if (Game::INSTANCE)
     {
         Game::INSTANCE->warteAufThread(100000000);
+        Game::INSTANCE->release();
+        Game::INSTANCE = 0;
     }
     dat->release();
     std::cout << "The server was shut down successfully.\n";

+ 26 - 1
FactoryCraft/StaticInitializerOrder.cpp

@@ -259,6 +259,17 @@ void initializeBlockTypes()
         ModelInfo("fluid", "fluids.ltdb/water.png", 6),
         "Water"))
         ->initializeDefault();
+    (new BasicBlockType(BlockTypeEnum::CRAFTING_TABLE,
+         ItemTypeEnum::CRAFTING_TABLE,
+         ModelInfo("cube",
+             {"blocks.ltdb/woodplanks.png",
+                 "blocks.ltdb/woodplanks.png",
+                 "blocks.ltdb/woodplanks.png",
+                 "blocks.ltdb/woodplanks.png",
+                 "blocks.ltdb/craftingtable.p",
+                 "blocks.ltdb/woodplanks.png"}),
+         "Crafting Table"))
+        ->initializeDefault(); // TODO: implement crafting table block type
 }
 
 void initializeItemTypes()
@@ -548,10 +559,24 @@ void initializeItemTypes()
                 50);
             item->setFoodEffect([](Entity* zEntity) {
                 zEntity->setHunger(zEntity->getHunger() + 0.5f);
-                zEntity->setThirst(zEntity->getThirst() + 1.f); // TODO: remove thirst addition when water exists
+                zEntity->setThirst(zEntity->getThirst() + 1.f); // TODO: remove thirst addition when drinkable water exists
             });
             return item;
         }));
+    
+    (new BasicBlockItemType(ItemTypeEnum::CRAFTING_TABLE,
+        "Crafting Table",
+        0,
+        0,
+        ModelInfo("itemCube",
+            {"blocks.ltdb/woodplanks.png",
+                "blocks.ltdb/woodplanks.png",
+                "blocks.ltdb/woodplanks.png",
+                "blocks.ltdb/woodplanks.png",
+                "blocks.ltdb/craftingtable.p",
+                "blocks.ltdb/woodplanks.png"}),
+        BlockTypeEnum::CRAFTING_TABLE)); // TODO: implement crafting table item
+                                         // type
 }
 
 void initializeEntityTypes()