Skip to content

Commit

Permalink
#12 and #14: crafting screens and recipes, experimenting with more co…
Browse files Browse the repository at this point in the history
…mplex yaml parsing, but still not there - yet
  • Loading branch information
fabio-t committed Nov 5, 2017
1 parent 2e7588c commit 586f642
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 88 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
2 changes: 2 additions & 0 deletions alone-rl.iml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.3.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.3.0" level="project" />
</component>
</module>
41 changes: 41 additions & 0 deletions data/crafting.yml
Original file line number Diff line number Diff line change
@@ -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]
Empty file removed data/flora/tree.yml
Empty file.
12 changes: 12 additions & 0 deletions data/items.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

stone:
name: a stone

branch:
name: a branch

trunk:
name: a tree trunk

boulder:
name: a boulder
Empty file removed data/items/branch.yml
Empty file.
Empty file removed data/items/stone.yml
Empty file.
Empty file removed data/items/trunk.yml
Empty file.
1 change: 1 addition & 0 deletions data/player.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

strength: 2
agility: 2
constitution: 2
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.1</version>
</dependency>

</dependencies>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/fabioticconi/alone/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

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
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

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<Name> mName;
ComponentMapper<Inventory> mInventory;
ComponentMapper<Equip> 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:";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 586f642

Please sign in to comment.