From 586f64282a3829d52ebd3b04b9d2bc98a3f1d85d Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Sun, 5 Nov 2017 21:15:24 +0100 Subject: [PATCH] #12 and #14: crafting screens and recipes, experimenting with more complex yaml parsing, but still not there - yet --- TODO.md | 2 - alone-rl.iml | 2 + data/crafting.yml | 41 +++++++++ data/flora/tree.yml | 0 data/items.yml | 12 +++ data/items/branch.yml | 0 data/items/stone.yml | 0 data/items/trunk.yml | 0 data/player.yml | 1 + pom.xml | 5 ++ .../com/github/fabioticconi/alone/Main.java | 3 + .../alone/screens/AbstractScreen.java | 54 ++++++++++++ .../alone/screens/CraftItemScreen.java | 62 ++++++++++++++ .../alone/screens/CraftScreen.java | 85 +++++++++++++++++++ .../alone/screens/DropScreen.java | 2 +- .../fabioticconi/alone/screens/EatScreen.java | 2 +- .../alone/screens/EquipScreen.java | 2 +- .../alone/screens/InventoryScreen.java | 47 ++++------ .../alone/screens/PlayScreen.java | 8 +- .../alone/screens/StartScreen.java | 9 +- .../alone/systems/BootstrapSystem.java | 82 +++++++++--------- .../alone/systems/CraftSystem.java | 85 +++++++++++++++++++ .../alone/systems/ItemSystem.java | 6 -- 23 files changed, 422 insertions(+), 88 deletions(-) create mode 100644 data/crafting.yml delete mode 100644 data/flora/tree.yml create mode 100644 data/items.yml delete mode 100644 data/items/branch.yml delete mode 100644 data/items/stone.yml delete mode 100644 data/items/trunk.yml create mode 100644 src/main/java/com/github/fabioticconi/alone/screens/CraftItemScreen.java create mode 100644 src/main/java/com/github/fabioticconi/alone/screens/CraftScreen.java create mode 100644 src/main/java/com/github/fabioticconi/alone/systems/CraftSystem.java diff --git a/TODO.md b/TODO.md index 27673a1..ee40c64 100644 --- a/TODO.md +++ b/TODO.md @@ -15,5 +15,3 @@ - LookScreen must show a message when moving around; the white colour of the targeting it's also horrible. It would be nice to make it better, eg a darker shade of whatever background colour there is? (a TileTransformer would work nicely maybe) - -- weapon damage must be included in the damage formula :) for now only strength it's used! diff --git a/alone-rl.iml b/alone-rl.iml index b4cb50e..c8d9c15 100644 --- a/alone-rl.iml +++ b/alone-rl.iml @@ -23,5 +23,7 @@ + + \ No newline at end of file diff --git a/data/crafting.yml b/data/crafting.yml new file mode 100644 index 0000000..3aa4910 --- /dev/null +++ b/data/crafting.yml @@ -0,0 +1,41 @@ + +branch: + name: a branch + #source: + # external: tree + +tree-trunk: + name: a tree trunk + #source: + # external: tree + tool: axe + +stone: + name: a stone + #source: + # external: boulder + tool: stone + n: 3 + +sharp-stone: + name: a sharp stone + source: stone + tool: stone + +#small-sharp-stone: +# name: a small, sharp stone +# source: [sharp-stone] +# tool: stone +# n: 2 +# +#stone-hammer: +# name: a stone hammer +# source: [stone, branch] +# +#stone-axe: +# name: a stone axe +# source: [sharp-stone, branch] +# +#stone-spear: +# name: a stone spear +# source: [small-sharp-stone, tree-trunk] diff --git a/data/flora/tree.yml b/data/flora/tree.yml deleted file mode 100644 index e69de29..0000000 diff --git a/data/items.yml b/data/items.yml new file mode 100644 index 0000000..f3ad73a --- /dev/null +++ b/data/items.yml @@ -0,0 +1,12 @@ + +stone: + name: a stone + +branch: + name: a branch + +trunk: + name: a tree trunk + +boulder: + name: a boulder diff --git a/data/items/branch.yml b/data/items/branch.yml deleted file mode 100644 index e69de29..0000000 diff --git a/data/items/stone.yml b/data/items/stone.yml deleted file mode 100644 index e69de29..0000000 diff --git a/data/items/trunk.yml b/data/items/trunk.yml deleted file mode 100644 index e69de29..0000000 diff --git a/data/player.yml b/data/player.yml index 0a5fbf0..3ff11d7 100644 --- a/data/player.yml +++ b/data/player.yml @@ -1,3 +1,4 @@ + strength: 2 agility: 2 constitution: 2 diff --git a/pom.xml b/pom.xml index 374d3f4..5f9269f 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,11 @@ 4.12 test + + com.fasterxml.jackson.core + jackson-databind + 2.3.1 + diff --git a/src/main/java/com/github/fabioticconi/alone/Main.java b/src/main/java/com/github/fabioticconi/alone/Main.java index f4fb914..f835cb6 100644 --- a/src/main/java/com/github/fabioticconi/alone/Main.java +++ b/src/main/java/com/github/fabioticconi/alone/Main.java @@ -98,6 +98,7 @@ public Main() throws IOException config.setSystem(PushSystem.class); config.setSystem(CrushSystem.class); config.setSystem(ThrowSystem.class); + config.setSystem(CraftSystem.class); // ai behaviours (passive) config.setSystem(FleeBehaviour.class); config.setSystem(GrazeBehaviour.class); @@ -115,6 +116,8 @@ public Main() throws IOException config.setSystem(EatScreen.class); config.setSystem(LookScreen.class); config.setSystem(EquipScreen.class); + config.setSystem(CraftScreen.class); + config.setSystem(CraftItemScreen.class); // last systems config.setSystem(DeadSystem.class); diff --git a/src/main/java/com/github/fabioticconi/alone/screens/AbstractScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/AbstractScreen.java index 7d2f92f..a5b7228 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/AbstractScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/AbstractScreen.java @@ -18,14 +18,26 @@ package com.github.fabioticconi.alone.screens; +import asciiPanel.AsciiPanel; +import com.artemis.managers.PlayerManager; +import com.artemis.utils.BitVector; +import com.github.fabioticconi.alone.components.Inventory; import net.mostlyoriginal.api.system.core.PassiveSystem; +import java.util.Collections; +import java.util.List; + +import static java.awt.event.KeyEvent.VK_A; +import static java.awt.event.KeyEvent.VK_Z; + /** * Author: Fabio Ticconi * Date: 01/11/17 */ public abstract class AbstractScreen extends PassiveSystem implements Screen { + PlayerManager pManager; + public enum Letter { a, @@ -61,4 +73,46 @@ public String toString() return name() + ")"; } } + + public abstract String header(); + + void drawHeader(final AsciiPanel terminal) + { + final String header = header(); + terminal.writeCenter(header, 2); + terminal.writeCenter(String.join("", Collections.nCopies(header.length(), "-")), 3); + } + + void drawList(final AsciiPanel terminal, final List list) + { + final int maxSize = AbstractScreen.Letter.values().length; + final int size = Math.min(maxSize, list.size()); + + for (int i = 0, starty = terminal.getHeightInCharacters() / 2 - size / 2; i < size; i++) + { + final String entry = list.get(i); + + terminal.writeCenter(entry, starty + (size < maxSize / 2 ? i * 2 : i)); + } + } + + /** + * Returns a number between 0 and 25, corresponding to letters A to Z (eg, possible selections). + * + * @param keys + * @return + */ + int getTargetIndex(final BitVector keys) + { + final int keyCode = keys.nextSetBit(VK_A); + + if (keyCode >= VK_A && keyCode <= VK_Z) + { + keys.clear(keyCode); + + return keyCode - VK_A; + } + + return -1; + } } diff --git a/src/main/java/com/github/fabioticconi/alone/screens/CraftItemScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/CraftItemScreen.java new file mode 100644 index 0000000..60f2024 --- /dev/null +++ b/src/main/java/com/github/fabioticconi/alone/screens/CraftItemScreen.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2017 Fabio Ticconi + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package com.github.fabioticconi.alone.screens; + +import asciiPanel.AsciiPanel; +import com.artemis.utils.BitVector; +import com.github.fabioticconi.alone.systems.ScreenSystem; + +import java.awt.event.KeyEvent; + +/** + * Author: Fabio Ticconi + * Date: 05/11/17 + */ +public class CraftItemScreen extends AbstractScreen +{ + ScreenSystem screen; + CraftScreen craftScreen; + + @Override + public String header() + { + return "Crafting item:"; + } + + @Override + public float handleKeys(final BitVector keys) + { + if (keys.get(KeyEvent.VK_ESCAPE)) + screen.select(PlayScreen.class); + + keys.clear(); + + return 0f; + } + + @Override + public void display(final AsciiPanel terminal) + { + drawHeader(terminal); + + terminal.writeCenter(craftScreen.craftItem, terminal.getHeightInCharacters()/2); + + // TODO + } +} diff --git a/src/main/java/com/github/fabioticconi/alone/screens/CraftScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/CraftScreen.java new file mode 100644 index 0000000..8140563 --- /dev/null +++ b/src/main/java/com/github/fabioticconi/alone/screens/CraftScreen.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2017 Fabio Ticconi + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package com.github.fabioticconi.alone.screens; + +import asciiPanel.AsciiPanel; +import com.artemis.ComponentMapper; +import com.artemis.managers.PlayerManager; +import com.artemis.utils.BitVector; +import com.github.fabioticconi.alone.components.Equip; +import com.github.fabioticconi.alone.components.Inventory; +import com.github.fabioticconi.alone.components.Name; +import com.github.fabioticconi.alone.systems.ActionSystem; +import com.github.fabioticconi.alone.systems.CraftSystem; +import com.github.fabioticconi.alone.systems.ItemSystem; +import com.github.fabioticconi.alone.systems.ScreenSystem; + +import java.awt.event.KeyEvent; + +/** + * Author: Fabio Ticconi + * Date: 05/11/17 + */ +public class CraftScreen extends AbstractScreen +{ + ComponentMapper mName; + ComponentMapper mInventory; + ComponentMapper mEquip; + + ScreenSystem screen; + ActionSystem sAction; + ItemSystem sItems; + CraftSystem sCraft; + + PlayerManager pManager; + + String craftItem = "Test"; + + @Override + public float handleKeys(final BitVector keys) + { + if (keys.get(KeyEvent.VK_ESCAPE)) + screen.select(PlayScreen.class); + else + { + final int pos = getTargetIndex(keys); + + if (pos >= 0) + screen.select(CraftItemScreen.class); + } + + keys.clear(); + + return 0f; + } + + @Override + public void display(final AsciiPanel terminal) + { + drawHeader(terminal); + + drawList(terminal, sCraft.getRecipeNames()); + } + + @Override + public String header() + { + return "Craft item:"; + } +} diff --git a/src/main/java/com/github/fabioticconi/alone/screens/DropScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/DropScreen.java index 0e5dddc..64bc51b 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/DropScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/DropScreen.java @@ -31,7 +31,7 @@ public float handleKeys(final BitVector keys) { final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId(); - final int targetId = getTarget(keys); + final int targetId = getItem(keys); if (targetId < 0) return super.handleKeys(keys); diff --git a/src/main/java/com/github/fabioticconi/alone/screens/EatScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/EatScreen.java index 400ad10..cc8023e 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/EatScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/EatScreen.java @@ -38,7 +38,7 @@ public float handleKeys(final BitVector keys) { final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId(); - final int targetId = getTarget(keys); + final int targetId = getItem(keys); if (targetId < 0) return super.handleKeys(keys); diff --git a/src/main/java/com/github/fabioticconi/alone/screens/EquipScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/EquipScreen.java index dfee73d..4a5d665 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/EquipScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/EquipScreen.java @@ -35,7 +35,7 @@ public float handleKeys(final BitVector keys) { final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId(); - final int targetId = getTarget(keys); + final int targetId = getItem(keys); if (targetId < 0) return super.handleKeys(keys); diff --git a/src/main/java/com/github/fabioticconi/alone/screens/InventoryScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/InventoryScreen.java index 6789173..364c4f6 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/InventoryScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/InventoryScreen.java @@ -20,7 +20,6 @@ import asciiPanel.AsciiPanel; import com.artemis.ComponentMapper; -import com.artemis.managers.PlayerManager; import com.artemis.utils.BitVector; import com.artemis.utils.IntBag; import com.github.fabioticconi.alone.components.Equip; @@ -31,6 +30,7 @@ import com.github.fabioticconi.alone.systems.ScreenSystem; import java.awt.event.KeyEvent; +import java.util.ArrayList; import java.util.Collections; import static java.awt.event.KeyEvent.VK_A; @@ -50,8 +50,6 @@ public abstract class InventoryScreen extends AbstractScreen ActionSystem sAction; ItemSystem sItems; - PlayerManager pManager; - @Override public float handleKeys(final BitVector keys) { @@ -70,53 +68,44 @@ public void display(final AsciiPanel terminal) terminal.clear(' '); - terminal.writeCenter(header(), 2); - terminal.writeCenter(String.join("", Collections.nCopies(header().length(), "-")), 3); + drawHeader(terminal); final Inventory inv = mInventory.get(playerId); - final int maxSize = AbstractScreen.Letter.values().length; - - final IntBag items = inv.items; - for (int i = 0, size = items.size(), starty = terminal.getHeightInCharacters() / 2 - size / 2; i < size; i++) + final ArrayList elements = new ArrayList<>(); + final IntBag items = inv.items; + for (int i = 0, size = items.size(); i < size; i++) { final int itemId = items.get(i); if (!canDraw(itemId)) continue; - final String entry = String.format("%s %s %s", - Letter.values()[i], - mName.get(itemId).name.toLowerCase(), - mEquip.has(itemId) ? " [WORN]" : ""); - - terminal.writeCenter(entry, starty + (size < maxSize / 2 ? i * 2 : i)); + elements.add(String.format("%s %s %s", + Letter.values()[i], + mName.get(itemId).name.toLowerCase(), + mEquip.has(itemId) ? " [WORN]" : "")); } + + drawList(terminal, elements); } public abstract String header(); public abstract boolean canDraw(final int entityId); - public int getTarget(final BitVector keys) + int getItem(final BitVector keys) { - final int keyCode = keys.nextSetBit(VK_A); + final int pos = getTargetIndex(keys); - final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId(); + if (pos < 0) + return -1; + final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId(); final Inventory i = mInventory.get(playerId); - if (keyCode >= VK_A && keyCode <= VK_Z) - { - keys.clear(keyCode); - - final int pos = keyCode - VK_A; - - if (pos < i.items.size()) - { - return i.items.get(pos); - } - } + if (pos < i.items.size()) + return i.items.get(pos); return -1; } diff --git a/src/main/java/com/github/fabioticconi/alone/screens/PlayScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/PlayScreen.java index d0e8ad3..cd00bdf 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/PlayScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/PlayScreen.java @@ -361,7 +361,7 @@ else if (sprite.shadowView) } // title: - terminal.writeCenter(properties.getProperty("name"), 1); + drawHeader(terminal); final Hunger hunger = mHunger.get(playerId); final Health health = mHealth.get(playerId); @@ -443,4 +443,10 @@ else if (sprite.shadowView) // player.messages.clear(); } + + @Override + public String header() + { + return properties.getProperty("name"); + } } diff --git a/src/main/java/com/github/fabioticconi/alone/screens/StartScreen.java b/src/main/java/com/github/fabioticconi/alone/screens/StartScreen.java index f2ca121..2071f27 100644 --- a/src/main/java/com/github/fabioticconi/alone/screens/StartScreen.java +++ b/src/main/java/com/github/fabioticconi/alone/screens/StartScreen.java @@ -64,10 +64,10 @@ public void display(final AsciiPanel terminal) { terminal.clear(' '); - final String title = title(); + final String header = header(); - terminal.writeCenter(title, 2); - terminal.writeCenter(String.join("", Collections.nCopies(title.length(), "-")), 3); + terminal.writeCenter(header, 2); + terminal.writeCenter(String.join("", Collections.nCopies(header.length(), "-")), 3); int y = terminal.getHeightInCharacters() / 2 - 4 * 2; terminal.writeCenter("(N)ew", y); @@ -84,7 +84,8 @@ public void display(final AsciiPanel terminal) // TODO credits? } - private String title() + @Override + public String header() { return String.format("%s v%s", properties.getProperty("name"), properties.getProperty("version")); } diff --git a/src/main/java/com/github/fabioticconi/alone/systems/BootstrapSystem.java b/src/main/java/com/github/fabioticconi/alone/systems/BootstrapSystem.java index d4c60b1..d8afc13 100644 --- a/src/main/java/com/github/fabioticconi/alone/systems/BootstrapSystem.java +++ b/src/main/java/com/github/fabioticconi/alone/systems/BootstrapSystem.java @@ -23,6 +23,7 @@ import com.artemis.utils.IntBag; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLParser; import com.github.fabioticconi.alone.behaviours.*; import com.github.fabioticconi.alone.components.*; import com.github.fabioticconi.alone.components.attributes.*; @@ -385,7 +386,7 @@ public void loadBody(final String filename, final EntityEdit edit) throws IOExce final InputStream fileStream = new FileInputStream(filename); final YAMLFactory factory = new YAMLFactory(); - final JsonParser parser = factory.createParser(fileStream); + final YAMLParser parser = factory.createParser(fileStream); int str = 0, agi = 0, con = 0, skin = 0, sight = 0; boolean herbivore = false, carnivore = false; @@ -399,50 +400,45 @@ public void loadBody(final String filename, final EntityEdit edit) throws IOExce if (name == null) break; - parser.nextToken(); // get in value + parser.nextToken(); // get value for this "name" - if (name.equals("strength")) + switch (name) { - str = parser.getIntValue(); - edit.create(Strength.class).value = Util.clamp(str, -2, 2); - } - else if (name.equals("agility")) - { - agi = parser.getIntValue(); - edit.create(Agility.class).value = Util.clamp(agi, -2, 2); - } - else if (name.equals("constitution")) - { - con = parser.getIntValue(); - edit.create(Constitution.class).value = Util.clamp(con, -2, 2); - } - else if (name.equals("skin")) - { - skin = parser.getIntValue(); - edit.create(Skin.class).value = Util.clamp(skin, -2, 2); - } - else if (name.equals("sight")) - { - sight = parser.getIntValue(); - edit.create(Sight.class).value = Util.clamp(sight, 1, 18); - } - else if (name.equals("herbivore")) - { - herbivore = parser.getBooleanValue(); - - if (herbivore) - edit.create(Herbivore.class); - } - else if (name.equals("carnivore")) - { - carnivore = parser.getBooleanValue(); - - if (carnivore) - edit.create(Carnivore.class); - } - else if (name.equals("underwater")) - { - edit.create(Underwater.class); + case "strength": + str = parser.getIntValue(); + edit.create(Strength.class).value = Util.clamp(str, -2, 2); + break; + case "agility": + agi = parser.getIntValue(); + edit.create(Agility.class).value = Util.clamp(agi, -2, 2); + break; + case "constitution": + con = parser.getIntValue(); + edit.create(Constitution.class).value = Util.clamp(con, -2, 2); + break; + case "skin": + skin = parser.getIntValue(); + edit.create(Skin.class).value = Util.clamp(skin, -2, 2); + break; + case "sight": + sight = parser.getIntValue(); + edit.create(Sight.class).value = Util.clamp(sight, 1, 18); + break; + case "herbivore": + herbivore = parser.getBooleanValue(); + + if (herbivore) + edit.create(Herbivore.class); + break; + case "carnivore": + carnivore = parser.getBooleanValue(); + + if (carnivore) + edit.create(Carnivore.class); + break; + case "underwater": + edit.create(Underwater.class); + break; } } diff --git a/src/main/java/com/github/fabioticconi/alone/systems/CraftSystem.java b/src/main/java/com/github/fabioticconi/alone/systems/CraftSystem.java new file mode 100644 index 0000000..a3bd464 --- /dev/null +++ b/src/main/java/com/github/fabioticconi/alone/systems/CraftSystem.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2017 Fabio Ticconi + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package com.github.fabioticconi.alone.systems; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLParser; +import com.github.fabioticconi.alone.screens.CraftItemScreen; +import net.mostlyoriginal.api.system.core.PassiveSystem; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +/** + * Author: Fabio Ticconi + * Date: 05/11/17 + */ +public class CraftSystem extends PassiveSystem +{ + HashMap recipes; + + public CraftSystem() throws IOException + { + loadRecipes(); + } + + public List getRecipeNames() + { + if (recipes == null || recipes.isEmpty()) + return List.of(); + + return new ArrayList<>(recipes.keySet()); + } + + private void loadRecipes() throws IOException + { + // TODO we can actually instantiate the factory and mapper in the Main and inject/Wire them + + final InputStream fileStream = new FileInputStream("data/crafting.yml"); + final YAMLFactory factory = new YAMLFactory(); + final ObjectMapper mapper = new ObjectMapper(factory); + + recipes = mapper.readValue(fileStream, new TypeReference>(){}); + + for (final Map.Entry entry : recipes.entrySet()) + { + System.out.println(entry.getKey() + " | " + entry.getValue()); + } + } + + public static class CraftItem + { + public String name; + public String source; + public String tool; + public int n = 1; + + @Override + public String toString() + { + return "CraftItem{" + "name='" + name + '\'' + ", source='" + source + '\'' + ", tool='" + tool + '\'' + + ", n=" + n + '}'; + } + } +} diff --git a/src/main/java/com/github/fabioticconi/alone/systems/ItemSystem.java b/src/main/java/com/github/fabioticconi/alone/systems/ItemSystem.java index 004dcf3..d51f467 100644 --- a/src/main/java/com/github/fabioticconi/alone/systems/ItemSystem.java +++ b/src/main/java/com/github/fabioticconi/alone/systems/ItemSystem.java @@ -178,12 +178,6 @@ public void doAction() return; } - if (i.items.size() >= AbstractScreen.Letter.values().length) - { - msg.send(actorId, new CannotMsg("get", "anything, your hands are full")); - return; - } - if (map.items.isEmpty(p.x, p.y)) { msg.send(actorId, new CannotMsg("get", "anything here"));