Skip to content

Commit

Permalink
#12: found a way of loading awt.Color from the yaml, and working towa…
Browse files Browse the repository at this point in the history
…rds loading all items by tag
  • Loading branch information
fabio-t committed Nov 13, 2017
1 parent 2cb4483 commit 2f358d7
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 19 deletions.
7 changes: 4 additions & 3 deletions alone-rl.iml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.1" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.0" 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" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.0" level="project" />
</component>
</module>
14 changes: 11 additions & 3 deletions data/items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ stone:
damageType: BLUNT
damage: 2
sprite:
c: 'o'
col: 5987163
c: 7
col:
red: 88
green: 88
blue: 88

branch:
name: a sturdy branch
Expand Down Expand Up @@ -37,7 +40,12 @@ boulder:
name: a big boulder
sprite:
c: '#'
col: 5987163 # change
col:
red: 88
green: 88
blue: 88
shadowView: true
obstacle: true

sharp-stone:
name: a sharp stone
Expand Down
19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,31 @@
<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>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.9.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/fabioticconi/alone/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.github.fabioticconi.alone.behaviours.*;
import com.github.fabioticconi.alone.constants.Options;
import com.github.fabioticconi.alone.screens.*;
Expand Down Expand Up @@ -75,6 +76,7 @@ public Main() throws IOException

final YAMLFactory factory = new YAMLFactory();
final ObjectMapper mapper = new ObjectMapper(factory)
.registerModule(new ParameterNamesModule())
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

final WorldConfiguration config;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.components;

import com.artemis.Component;

/**
* Author: Fabio Ticconi
* Date: 13/11/17
*/
public class Obstacle extends Component
{
public Obstacle(final boolean state)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@ public int makeStone(final Point p)

public int makeStone(final int x, final int y)
{
final int id = world.create();

final EntityEdit edit = world.edit(id);
edit.create(Position.class).set(x, y);
edit.create(Sprite.class).set('o', Color.DARK_GRAY.brighter());
edit.create(Weapon.class).set(WeaponType.BLUNT, 1);
edit.create(Wearable.class);
edit.add(new Name("A round stone", "stone"));

map.items.set(id, x, y);

return id;
return sItem.makeItem("stone", x, y);
}

public int makeBoulder(final Point p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ItemSystem extends PassiveSystem
ComponentMapper<Wearable> mWearable;
ComponentMapper<Armour> mArmour;
ComponentMapper<Name> mName;
ComponentMapper<Obstacle> mObstacle;

MessageSystem msg;
MapSystem map;
Expand Down Expand Up @@ -107,6 +108,45 @@ public void loadTemplates() throws IOException
}
}

/**
* It instantiates an object of the given type and places at that Point.
*
* @param tag
* @param p
* @return
*/
public int makeItem(final String tag, final Point p)
{
return makeItem(tag, p.x, p.y);
}

/**
* It instantiates an object of the given type and places at that position.
*
* @param tag
* @param x
* @param y
* @return
*/
public int makeItem(final String tag, final int x, final int y)
{
final int id = makeItem(tag);

if (id < 0)
return id;

final Point p = map.getFirstTotallyFree(x, y, -1);

mPos.create(id).set(p.x, p.y);

if (mObstacle.has(id))
map.obstacles.set(id, p.x, p.y);
else
map.items.set(id, p.x, p.y);

return id;
}

public int makeItem(final String tag)
{
try
Expand Down Expand Up @@ -135,6 +175,8 @@ public int makeItem(final String tag)
edit.add(template.weapon);
if (template.sprite != null)
edit.add(template.sprite);
if (template.obstacle != null)
edit.add(template.obstacle);

return id;
} catch (final IOException e)
Expand All @@ -153,6 +195,7 @@ public static class ItemTemplate
public Wearable wearable;
public Weapon weapon;
public Sprite sprite;
public Obstacle obstacle;
}

public GetAction get(final int actorId)
Expand Down

0 comments on commit 2f358d7

Please sign in to comment.