Skip to content

Commit 913c1f8

Browse files
committed
quick
1 parent 890c547 commit 913c1f8

File tree

11 files changed

+82
-152
lines changed

11 files changed

+82
-152
lines changed

CharActor/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ._charactor import dicts as _dicts
44
from ._charactor import create, BaseCharacters as _BaseCharacters, character_bank
55
from ._objects._items import _Armory, _Goods
6-
from . import _entity
76

87
log('Initializing CharActor.')
98
log('Initializing character bank.')

CharActor/__log__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def log(message):
1717
if module.__name__ in ['__main__', 'CharActor']:
1818
return logger.log(99, message)
1919
caller = frame[3]
20-
return logger.log(99, f'{module.__name__[-module.__name__[::-1].index('.'):]}: {caller}: {message}')
20+
return logger.log(99, f'{module.__name__[-module.__name__[::-1].index("."):]}: {caller}: {message}')

CharActor/_charactor/actor/_actor/_base_character.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from ...._entity import _base_entity
21
from ._base_class_actors import *
32
from ._base_race_actors import *
43

@@ -15,9 +14,4 @@
1514

1615
for k, v in _base_characters.items():
1716
_char_list.extend(f'{k}{K}' for K in v.keys())
18-
19-
for race in RACE_ATTRIBUTES:
20-
race = race.replace('-', '')
21-
for role in ROLE_ATTRIBUTES:
22-
setattr(_base_entity, f'{race}{role}', _base_characters[race][role])
23-
17+

CharActor/_charactor/actor/_actor/base_actor.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from random import randint as _randint
66
from typing import Optional as _Optional, Any
77

8-
from entyty import AbstractEntity
8+
from entyty import _AbstractEntity as AbstractEntity
99

1010
import getch
1111
import pyglet.window as _window
@@ -450,7 +450,9 @@ def _init_inventory(self):
450450
log(f'Adding starting equipment: {self._role._starting_equipment}')
451451
for item in self._role._starting_equipment + self._background.equipment:
452452
if isinstance(item, list):
453-
if len(item) > 1 and (item[1] in Armory or item[1] in Goods):
453+
if item == []:
454+
continue
455+
elif len(item) > 1 and (item[1] in Armory or item[1] in Goods):
454456
log(f'Adding {item[0]} {item[1]}')
455457
for _ in range(item[0]):
456458
self.inventory.add_item(item[1])
@@ -570,7 +572,7 @@ class BaseCharacter(BaseActor):
570572
"""
571573
log('Initializing BaseCharacter class.')
572574
AbstractEntity.dispatcher.register_event_type('on_turn_end')
573-
575+
dispatcher = AbstractEntity.dispatcher
574576
def __init__(self, name, background: str, alignment: str, grid=None):
575577
from entyty import GridEntity
576578
character_class = self.__class__.__name__
@@ -591,6 +593,7 @@ def __init__(self, name, background: str, alignment: str, grid=None):
591593
self._create_properties()
592594
self._actions = {'move': {i: {'direction': None, 'from': None, 'distance': None, 'to': None} for i in range(self.speed//5)},
593595
'attack': {'target': None, 'weapon': None, 'result': None}, 'free': [], 'quick': []}
596+
self._action_history = []
594597
self._is_turn = False
595598
self._nearby_items = {}
596599
self._target = None
@@ -620,7 +623,7 @@ def _create_properties(self):
620623
setattr(self.__class__, 'grid_entity', property(lambda self: self._grid_entity))
621624
properties = {
622625
'movements': self.grid_entity.movements,
623-
'movements_remaining': self.grid_entity._movements_remaining,
626+
'movements_remaining': self.grid_entity.movements_remaining,
624627
'movement_queue': self.grid_entity.movement_queue,
625628
'cell': self.grid_entity.cell,
626629
'cell_name': self.grid_entity.cell_name,
@@ -634,6 +637,7 @@ def _create_properties(self):
634637
for attr, value in properties.items():
635638
setattr(self, attr, value)
636639
setattr(self.__class__, attr, property(lambda self, attr=attr: getattr(self.grid_entity, attr)))
640+
self._push_handlers(on_turn_end=self.grid_entity.end_turn)
637641
else:
638642
for attr in ['movements', 'movements_remaining', 'movement_queue', 'cell', 'cell_name', 'cell_history', 'last_cell', 'x', 'y', 'position', 'path']:
639643
delattr(self, attr)
@@ -675,7 +679,9 @@ def _on_turn_change(self, actor):
675679
self._is_turn = True
676680

677681
def end_turn(self):
678-
self.dispatcher.dispatch_event('on_turn_end', self.actions)
682+
self._action_history.append(self.actions)
683+
self.grid_entity.end_turn()
684+
self.actions = None
679685

680686
def _join_grid(self, grid):
681687
from entyty import GridEntity
@@ -697,10 +703,13 @@ def _set_target(self, target):
697703

698704
def move(self, direction):
699705
if direction in ['north_west', 'north', 'north_east', 'east', 'south_east', 'south', 'south_west', 'west']:
700-
self.grid_entity.move_in_direction(direction)
706+
mvmnt_index = self.grid_entity.move_in_direction(direction)
701707
self.actions['move'] = self.grid_entity.actions['move']
702-
return f'--> {self.actions["move"][len(self.actions["move"]) - 1]["to"]}'
703-
708+
if mvmnt_index is not None:
709+
return f'{self.actions["move"][mvmnt_index]["from"]} --> {self.actions["move"][mvmnt_index]["to"]}'
710+
else:
711+
return f'Cannot move {direction}.'
712+
704713
def attack(self):
705714
if 'attack' in self._actions.keys():
706715
print('Already attacked this turn.')

CharActor/_objects/_items/catalogues.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _get_class(self, item_name: str):
159159
return self.items[item_name]
160160

161161
def _create_grid_meta(self, item_name, item_class):
162-
return type(item_name.replace(" ", "").replace(",", "_").replace("-",""), (GridItem, item_class), {'dispatcher': EventDispatcher()})
162+
return type(item_name.replace(" ", "").replace(",", "_").replace("-",""), (item_class, ), {'dispatcher': EventDispatcher()})
163163

164164
def _create_item_classes(self):
165165
for _item_name, _item_attr in _GENERAL_ITEMS_DICT.items():
@@ -192,23 +192,18 @@ def get(self, item_name: str, grid: object = None, cell: object = None):
192192
return item
193193
return self[item_name]
194194

195-
# TODO Rename this here and in `get`
196195
def _create_griditem(self, item_name, grid, cell: _Union[str, type(Cell)]):
197-
item_instance = self[item_name]
198-
griditem_instance = item_instance._materialize(grid, cell)
199-
200-
# item_class = self._get_class(item_name)
201-
# combined_class = self._create_grid_meta(item_name, item_class)
202-
# cell = grid[cell] if cell is not None and isinstance(cell, str) else cell
203-
# griditem_instance = combined_class(grid, item_name, cell)
196+
item_class = self._get_class(item_name)
197+
item_meta = self._create_grid_meta(item_name, item_class)
198+
cell = grid[cell] if cell is not None and isinstance(cell, str) else cell
199+
griditem_instance = GridItem(grid, item_name, cell)
204200
if self._grid_instances.get(item_name, None) is not None:
205201
item_count = 1 + sum(bool(key.startswith(item_name))
206202
for key in list(self._grid_instances.keys()))
207203
self._grid_instances[f'{item_name}{item_count}'] = griditem_instance
208204
else:
209205
self._grid_instances[item_name] = griditem_instance
210-
return griditem_instance
211-
206+
return griditem_instance
212207

213208

214209
Armory = _Armory()

CharActor/_objects/_items/item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_TRADE_ITEMS_DICT = load_dict('trade_items')
3939

4040

41-
class AbstractItem(ABC, metaclass=type):
41+
class AbstractItem(ABC):
4242
_item_id = None
4343
_name = None
4444
_category = None

entity.log

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
w - Initializing abstract entity class.
2+
w - Initializing base entity class.
3+
w - Initializing entity class.
4+
w - Initializing logical entity class.
5+
w - Initializing visual entity class.
6+
w - Initializing abstract grid entity class.
7+
w - Initializing abstract entity class.
8+
w - Initializing base entity class.
9+
w - Initializing entity class.
10+
w - Initializing logical entity class.
11+
w - Initializing visual entity class.
12+
w - Initializing abstract grid entity class.
13+
w - Initializing abstract entity class.
14+
w - Initializing base entity class.
15+
w - Initializing entity class.
16+
w - Initializing logical entity class.
17+
w - Initializing visual entity class.
18+
w - Initializing abstract grid entity class.

gridengine.log

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
2023-11-03 00:17:28,824 - GRIDENGINE - __log__ - Setting saves directory ...
2-
2023-11-03 00:17:28,824 - GRIDENGINE - __log__ - Saves directory set to /devel/boss/envs/CharActor/grid_engine/_saves/
1+
2023-11-04 17:44:39,794 - GRIDENGINE - __log__ - Setting saves directory ...
2+
2023-11-04 17:44:39,794 - GRIDENGINE - __log__ - Saves directory set to /devel/boss/envs/CharActor/grid_engine/_saves/
3+
2023-11-04 17:44:41,135 - GRIDENGINE - __log__ - process_grid(int)
4+
2023-11-04 17:44:41,135 - GRIDENGINE - __log__ - get_row_strings(int)
5+
2023-11-04 17:44:41,135 - GRIDENGINE - __log__ - generate_row_strings(int)
6+
2023-11-04 17:44:41,139 - GRIDENGINE - __log__ - get_column_strings(int)
7+
2023-11-04 17:44:41,139 - GRIDENGINE - __log__ - generate_column_strings(int)
8+
2023-11-04 17:44:41,139 - GRIDENGINE - __log__ - get_cell_strings(list)
9+
2023-11-04 17:44:41,139 - GRIDENGINE - __log__ - generate_cell_strings(list)
10+
2023-11-04 17:44:41,143 - GRIDENGINE - __log__ - get_cell_coordinates(int)
11+
2023-11-04 17:44:41,161 - GRIDENGINE - __log__ - get_grid_dict(list)
12+
2023-11-04 17:44:41,475 - GRIDENGINE - __log__ - generate_quadrant_coordinates(int)
13+
2023-11-04 17:44:41,475 - GRIDENGINE - __log__ - get_quadrant_indices(list)
14+
2023-11-04 17:44:41,510 - GRIDENGINE - __log__ - generate_adjacency(dict)
15+
2023-11-04 17:44:41,961 - GRIDENGINE - __log__ - _init_terrain(TerrainGridBlueprint)
16+
2023-11-04 17:44:42,269 - GRIDENGINE - __log__ - _set_base_terrain(TerrainGridBlueprint)
17+
2023-11-04 17:44:42,323 - GRIDENGINE - __log__ - _adjust_passability(TerrainGridBlueprint)
18+
2023-11-04 17:44:44,220 - GRIDENGINE - __log__ - set_rivers(Terraformer)
19+
2023-11-04 17:44:44,221 - GRIDENGINE - __log__ - generate_realistic_river(Terraformer)
20+
2023-11-04 17:44:44,221 - GRIDENGINE - __log__ - get_river_by_walk(Terraformer)
21+
2023-11-04 17:44:44,223 - GRIDENGINE - __log__ - expand_river_path(Terraformer)
22+
2023-11-04 17:44:44,250 - GRIDENGINE - __log__ - generate_realistic_river(Terraformer)
23+
2023-11-04 17:44:44,250 - GRIDENGINE - __log__ - get_river_by_walk(Terraformer)
24+
2023-11-04 17:44:44,251 - GRIDENGINE - __log__ - expand_river_path(Terraformer)
25+
2023-11-04 17:44:44,259 - GRIDENGINE - __log__ - get_river_banks(Terraformer)
26+
2023-11-04 17:44:44,263 - GRIDENGINE - __log__ - expand_riverbanks(Terraformer)

0 commit comments

Comments
 (0)