Skip to content

Commit

Permalink
#14: probably finished the basic loading of the crafting recipes, now…
Browse files Browse the repository at this point in the history
… it must be linked to 'item tags'
  • Loading branch information
fabio-t committed Nov 8, 2017
1 parent a1ed9e5 commit 17a2d51
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 52 deletions.
57 changes: 21 additions & 36 deletions data/crafting.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@

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
tools: stone

small-sharp-stone:
name: a small, sharp stone
source: sharp-stone
tools: stone
n: 2

stone-hammer:
name: a stone hammer
source: [stone, branch, vine]
tools: stone

stone-axe:
name: a stone axe
source: [sharp-stone, branch, vine]
tools: 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]
stone-spear:
name: a stone spear
source: [small-sharp-stone, trunk, vine]
tools: stone
12 changes: 12 additions & 0 deletions data/items.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@

stone:
name: a stone
sprite:
c: 'o'
col:

branch:
name: a branch
sprite:
c: '/'
col:

trunk:
name: a tree trunk
sprite:
c: '-'
col:

boulder:
name: a boulder
sprite:
c: '#'
col:
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,26 @@ else if (keys.get(KeyEvent.VK_F2))
}
else if (keys.get(KeyEvent.VK_SPACE))
{
keys.clear();

if (keys.get(KeyEvent.VK_CONTROL))
{
// Ctrl+Space means we are toggling the real-time mode
Main.realtime = !Main.realtime;
// as well as toggling the pause, of course
Main.paused = !Main.paused;
}
else if (Main.realtime)
{
// in real-time mode, SPACE just means pausing

keys.clear();
Main.pause();
}
else
{
keys.clear();

Main.paused = Main.realtime && !Main.paused;
// in turn-based mode, SPACE means "unpause", which we achieve by
// simply setting a player action equal to the world delta.
// this will

return world.delta;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

package com.github.fabioticconi.alone.systems;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
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;
Expand Down Expand Up @@ -56,11 +54,14 @@ 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);
final InputStream fileStream = new FileInputStream("data/crafting.yml");
final YAMLFactory factory = new YAMLFactory();
final ObjectMapper mapper = new ObjectMapper(factory)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

recipes = mapper.readValue(fileStream, new TypeReference<HashMap<String, CraftItem>>(){});
recipes = mapper.readValue(fileStream, new TypeReference<HashMap<String, CraftItem>>()
{
});

for (final Map.Entry<String, CraftItem> entry : recipes.entrySet())
{
Expand All @@ -70,16 +71,16 @@ private void loadRecipes() throws IOException

public static class CraftItem
{
public String name;
public String source;
public String tool;
public String name;
public String[] source;
public String[] tools;
public int n = 1;

@Override
public String toString()
{
return "CraftItem{" + "name='" + name + '\'' + ", source='" + source + '\'' + ", tool='" + tool + '\'' +
", n=" + n + '}';
return "CraftItem{" + "name='" + name + '\'' + ", source='" + Arrays.toString(source) + '\'' + ", tools='" +
Arrays.toString(tools) + '\'' + ", n=" + n + '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public MapSystem() throws IOException
obstacles = new SingleGrid(Options.MAP_SIZE_X, Options.MAP_SIZE_Y);
items = new SingleGrid(Options.MAP_SIZE_X, Options.MAP_SIZE_Y);

// TODO: we should make Cell a class, and obviously use a pool.
// This way we can load the cells from a yaml file, with their thresholds, colours, characters etc,
// and then we aren't stuck anymore with a few discrete terrain types but we can colour with a gradient,
// for example.
// movement costs should also be part of this cell.

float value;

for (int x = 0; x < Options.MAP_SIZE_X; x++)
Expand Down

0 comments on commit 17a2d51

Please sign in to comment.