Skip to content

Commit 3afa092

Browse files
committed
Merge branch 'storage-rework-rework' (PR #39)
2 parents 6db1117 + 9f6b8c7 commit 3afa092

38 files changed

+458
-117
lines changed

data/worlds/chaosdorf/areas/cave.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "Cave"
1+
name = "cave"
22
description = "a comfy room with sofas and a tv"
33

44
[[contents]]

data/worlds/chaosdorf/areas/conference-room.toml renamed to data/worlds/chaosdorf/areas/conference room.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "confeerence room"
1+
name = "conference room"
22
description = "a room with a giant tv, a conference table, and a window."
33

44
[[contents]]

data/worlds/chaosdorf/areas/floor.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ obvious = true
1010
[[contents]]
1111
kind = "gateway"
1212
name = "everyones toilet door"
13-
target = "everyones-toilet"
13+
target = "everyones toilet"
1414
obvious = true
1515

1616
[[contents]]
1717
kind = "gateway"
1818
name = "flinta toilet door"
19-
target = "flinta-toilet"
19+
target = "flinta toilet"
2020
obvious = true
2121

2222
[[contents]]
2323
kind = "gateway"
2424
name = "premium toilet door"
25-
target = "premium-toilet"
25+
target = "premium toilet"
2626
obvious = true
2727

2828
[[contents]]
@@ -34,7 +34,7 @@ obvious = true
3434
[[contents]]
3535
kind = "gateway"
3636
name = "conference room door"
37-
target = "conference-room"
37+
target = "conference room"
3838
obvious = true
3939

4040
[[contents]]

data/worlds/chaosdorf/areas/lounge.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "Lounge"
1+
name = "lounge"
22
description = "a place to eat and socialize"
33

44
[[contents]]

data/worlds/chaosdorf/world.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name = "Chaosdorf"
1+
name = "chaosdorf"
22
language = "en"
3-
areas = ["cave", "lounge", "kitchen", "hackcenter", "floor", "elab", "conference-room", "everyones-toilet", "flinta-toilet", "premium-toilet", "wetlab"]
3+
areas = ["cave", "lounge", "kitchen", "hackcenter", "floor", "elab", "conference room", "everyones toilet", "flinta toilet", "premium toilet", "wetlab"]
44
spawn = "cave"
55
intro_text = """
66
You awake confused from a deep sleep.

data/worlds/test/areas/test_area.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name = "test area"
2+
description = "an area could be a dungeon, a room, a castle"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test enemy"
2+
description = "an enemy is a character which will attack the player"
3+
health = 100
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test player"
2+
description = "the playable character"
3+
health = 100
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test character"
2+
description = "a character is a person in the world"
3+
health = 100
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test container"
2+
description = "a container is an item which has an inventory"
3+
capacity = 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test entity"
2+
description = "an entity is an abstract thing"
3+
obvious = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "test gateway"
2+
description = "a gateway is a portal to another area"
3+
target = "test area"
4+
locked = false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test inventory"
2+
description = "an inventory can contain items"
3+
capacity = 10
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "test armour"
2+
description = "armour is an item which can be worn by the player"
3+
obvious = true
4+
moveable = true
5+
carryable = true
6+
armour_type = "head"
7+
defense = 10
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "test key"
2+
description = "a key is an item which can be used by the player to open doors"
3+
obvious = true
4+
key_id = "dungeon key 1"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "test weapon"
2+
description = "a weapon is an item which can be used by the player to damage his enemies"
3+
damage = 10

data/worlds/test/items/test_item.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name = "test item"
2+
description = "an item is a entity in the world, which the player can interact with"
3+
obvious = true
4+
moveable = true
5+
carryable = true

data/worlds/test/world.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "test"
2+
language = "en"
3+
areas = ["test area"]
4+
spawn = "test area"

src/fantasy_forge/area.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
"""An Area is a place in the world, containing NPCs, Items and connections to other areas."""
2+
13
from __future__ import annotations
24

5+
import logging
36
from pathlib import Path
47
from typing import TYPE_CHECKING, Any, Iterator, Self
58

@@ -8,6 +11,8 @@
811
from fantasy_forge.entity import Entity
912
from fantasy_forge.utils import UniqueDict
1013

14+
logger = logging.getLogger(__name__)
15+
1116

1217
class Area(Entity):
1318
"""An Area is a place in the world, containing NPCs, Items and connections to other areas."""
@@ -16,6 +21,14 @@ class Area(Entity):
1621
contents: UniqueDict[str, Entity]
1722

1823
def __init__(self: Self, messages: Messages, config_dict: dict[str, Any]):
24+
"""
25+
config_dict contents
26+
27+
inherited from Entity
28+
'name' (str): name of the entity
29+
'description' (str): description of the entity (default: "")
30+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
31+
"""
1932
super().__init__(messages, config_dict)
2033
self.contents = UniqueDict()
2134

src/fantasy_forge/armour.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Armour class
2+
3+
An Armour is an item which can be worn by Characters and grants protection.
4+
"""
5+
16
from __future__ import annotations
27

38
from typing import TYPE_CHECKING, Self
@@ -13,16 +18,35 @@
1318

1419

1520
class Armour(Item):
21+
"""An Armour object."""
22+
1623
armour_type: str
1724
defense: int
1825

1926
__important_attributes__ = ("name", "armour_type", "defense")
27+
__attributes__ = {**Item.__attributes__, "armour_type": str, "defense": int}
2028

2129
def __init__(self, messages: Messages, config_dict):
30+
"""
31+
config_dict contents
32+
'armour_type' (str): armour slot ("head", "torso", "legs", "feet")
33+
'defense' (int): defense points gained by armour
34+
35+
inherited from Item:
36+
'moveable' (bool): can the item be moved by the player (default: True)
37+
'carryable' (bool): can the item be put in the inventory by the player (default: True)
38+
39+
inherited from Entity
40+
'name' (str): name of the entity
41+
'description' (str): description of the entity (default: "")
42+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
43+
"""
44+
# set armour type
2245
a_type: str = config_dict.pop("armour_type")
2346
assert a_type in ARMOUR_TYPES
2447
self.armour_type = a_type
2548
self.defense = config_dict.pop("defense")
49+
2650
super().__init__(messages, config_dict)
2751

2852
def to_dict(self: Self) -> dict:

src/fantasy_forge/character.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Character class
2+
3+
A character is a living entity, which can interact with other entities or characters.
4+
"""
5+
16
from __future__ import annotations
27

38
from typing import TYPE_CHECKING, Any, Self
@@ -26,20 +31,32 @@ class Character(Entity):
2631
"""A character in the world."""
2732

2833
__important_attributes__ = ("name", "health", "alive")
34+
__attributes__ = {**Entity.__attributes__, "health": int, "alive": bool}
2935

3036
health: int
3137
inventory: Inventory
3238
main_hand: Weapon | None
3339
_alive: bool
3440

3541
def __init__(self: Self, messages: Messages, config_dict: dict[str, Any]) -> None:
42+
"""
43+
config_dict contents
44+
'health' (int): health points
45+
46+
inherited from Entity:
47+
'name' (str): name of the entity
48+
'description' (str): description of the entity (default: "")
49+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
50+
"""
51+
3652
self.health = config_dict.pop("health")
3753
self.inventory = Inventory(messages, BASE_INVENTORY_CAPACITY)
3854
self.main_hand = None
3955
super().__init__(messages, config_dict)
4056

4157
@property
4258
def alive(self: Self) -> bool:
59+
"""Return True if the character is alive."""
4360
self._alive = self.health > 0
4461
return self._alive
4562

@@ -58,6 +75,7 @@ def attack(self: Self, target: Character) -> None:
5875
)
5976

6077
def on_attack(self: Self, weapon: Weapon):
78+
"""Handles an incoming attack."""
6179
self.health -= weapon.damage
6280

6381
def _on_death(self: Self, player: Player):
@@ -81,6 +99,7 @@ def _on_death(self: Self, player: Player):
8199
for loot_item in self.inventory.pop_all():
82100
player.area.contents[loot_item.name] = loot_item
83101
player.seen_entities[loot_item.name] = loot_item
102+
84103
self.messages.to(
85104
[player],
86105
"attack-drop-single",

src/fantasy_forge/container.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1+
"""Container class
2+
3+
A container is an item in the world which holds an inventory.
4+
"""
5+
16
from typing import Any, Self
27

3-
from fantasy_forge.entity import Entity
48
from fantasy_forge.inventory import Inventory
5-
from fantasy_forge.world import World
9+
from fantasy_forge.item import Item
10+
11+
12+
class Container(Inventory, Item):
13+
"""Container object."""
14+
15+
__important_attributes__ = (*Item.__important_attributes__, "capacity")
16+
__attributes__ = {**Inventory.__attributes__, **Item.__attributes__}
17+
18+
def __init__(
19+
self: Self, config_dict: dict[str, Any], l10n: FluentLocalization
20+
) -> None:
21+
"""
22+
config_dict contents
23+
inherited from Inventory
24+
'capacity' (int): maximum capacity of the inventory
25+
26+
inherited from Item
27+
'moveable' (bool): can the item be moved by the player (default: True)
28+
'carryable' (bool): can the item be put in the inventory by the player (default: True)
629
30+
inherited from Entity
31+
'name' (str): name of the entity
32+
'description' (str): description of the entity (default: "")
33+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
34+
"""
35+
Inventory.__init__(self, config_dict, l10n)
36+
Item.__init__(self, config_dict, l10n)
737

8-
class Container(Entity, Inventory):
9-
__important_attributes__ = ("name", "capacity")
1038

11-
def __init__(self: Self, world: World, config_dict: dict[str, Any]):
12-
capacity: int = config_dict.get("capacity", 10)
13-
Entity.__init__(world, capacity)
14-
Inventory.__init__(world, config_dict)
39+
if TYPE_CHECKING:
40+
from fluent.runtime import FluentLocalization

src/fantasy_forge/enemy.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
from typing import Any, Self
1+
"""Enemy class
22
3+
An enemy is a hostile character which will attack the player on contact.
4+
"""
5+
6+
from typing import TYPE_CHECKING, Any, Self
37
from fantasy_forge.character import Character, bare_hands
48
from fantasy_forge.item import Item
59
from fantasy_forge.messages import Messages
610

711

812
class Enemy(Character):
913
"""An enemy is a person which will fight back."""
10-
1114
def __init__(self: Self, messages: Messages, config_dict: dict[str, Any]):
15+
"""
16+
config_dict contents
17+
'loot' (list[Item]): items dropped after death
18+
19+
inherited from Character
20+
'health' (int): health points
21+
22+
inherited from Entity:
23+
'name' (str): name of the entity
24+
'description' (str): description of the entity (default: "")
25+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
26+
"""
1227
super().__init__(messages, config_dict)
1328
for item_dict in config_dict.get("loot", []):
1429
self.inventory.add(Item(messages, item_dict))

src/fantasy_forge/entity.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1+
"""Entity class
2+
3+
An entity is an abstract object in the world.
4+
Each entity is identifiable by its name.
5+
"""
6+
17
from __future__ import annotations
28

39
from typing import TYPE_CHECKING, Any, Self
410

511

612
class Entity:
7-
"""An Entity is an abstract object in the world."""
13+
"""An Entity object"""
814

915
__important_attributes__ = ("name",)
16+
__attributes__: dict[str, type] = {"name": str, "description": str, "obvious": bool}
1017

1118
messages: Messages
1219
name: str
1320
description: str
1421
obvious: bool # obvious entities are seen when entering the room
22+
l10n: FluentLocalization
1523

1624
def __init__(
1725
self: Self,
1826
messages: Messages,
1927
config_dict: dict[str, Any],
2028
) -> None:
29+
"""
30+
config_dict contents
31+
'name' (str): name of the entity
32+
'description' (str): description of the entity (default: "")
33+
'obvious'(bool): whether the entity will be spotted immediately (default: False)
34+
"""
2135
self.messages = messages
2236
self.name = config_dict.pop("name")
2337
self.description = config_dict.pop("description", "")
2438
self.obvious = config_dict.pop("obvious", False)
25-
39+
2640
def on_look(self: Self, actor: Player):
2741
actor.shell.stdout.write(self.description + "\n")
2842

@@ -48,6 +62,7 @@ def __str__(self: Self) -> str:
4862
return self.name
4963

5064
def to_dict(self: Self) -> dict:
65+
"""Returns entity attributes as a dictionary."""
5166
entity_dict: dict = {"name": self.name, "description": self.description}
5267
return entity_dict
5368

0 commit comments

Comments
 (0)