From 53f81ed62f39433ac73c9c9b76d896edf7add482 Mon Sep 17 00:00:00 2001 From: Shi Johnson-Bey Date: Thu, 11 May 2023 08:35:41 -0500 Subject: [PATCH 1/3] fixed README and typing errors --- README.md | 2 +- src/neighborly/components/business.py | 9 ++++++--- src/neighborly/core/roles.py | 2 +- src/neighborly/plugins/defaults/create_town.py | 12 +++--------- src/neighborly/plugins/talktown/spawn_tables.py | 5 +---- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f08be25..579a30e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ src="https://user-images.githubusercontent.com/11076525/165836171-9ffdea6e-1633-440c-be06-b46e1e3e4e04.png" >
- Neighborly (v0.10.0) + Neighborly

diff --git a/src/neighborly/components/business.py b/src/neighborly/components/business.py index 3593067..df20017 100644 --- a/src/neighborly/components/business.py +++ b/src/neighborly/components/business.py @@ -341,9 +341,12 @@ def get_open_positions(self) -> List[str]: List[str] All the names of all open positions at the business. """ - return sum( - [[title] * count for title, count in self._open_positions.items()], [] - ) + open_positions: List[str] = [] + + for title, count in self._open_positions.items(): + open_positions.extend([title] * count) + + return open_positions def get_employees(self) -> List[int]: """Get all current employees. diff --git a/src/neighborly/core/roles.py b/src/neighborly/core/roles.py index 970e2ca..1de9e17 100644 --- a/src/neighborly/core/roles.py +++ b/src/neighborly/core/roles.py @@ -121,7 +121,7 @@ def get(self, role_name: str) -> Optional[GameObject]: def __len__(self) -> int: return len(self._roles) - def __bool__(self) -> int: + def __bool__(self) -> bool: return bool(self._roles) def __getitem__(self, role_name: str) -> GameObject: diff --git a/src/neighborly/plugins/defaults/create_town.py b/src/neighborly/plugins/defaults/create_town.py index 91eecc6..4617986 100644 --- a/src/neighborly/plugins/defaults/create_town.py +++ b/src/neighborly/plugins/defaults/create_town.py @@ -36,19 +36,13 @@ def load_spawn_table(cls, table_type: str, file_path: _AnyPath): The file path to the file to load data from. """ with open(file_path, "r") as csv_file: - df = pandas.read_csv(csv_file) + df = pandas.read_csv(csv_file) # type: ignore if table_type not in cls.prefab_data: cls.prefab_data[table_type] = [] - for _, row in df.iterrows(): - cls.prefab_data[table_type].append(row.to_dict()) - - pass - # next(reader, None) # skip the headers - - # for row in reader: - # cls.prefab_data[table_type].append(row) + for _, row in df.iterrows(): # type: ignore + cls.prefab_data[table_type].append(row.to_dict()) # type: ignore def process(self, *args: Any, **kwargs: Any) -> None: settlement = spawn_settlement(self.world, self.settlement_prefab) diff --git a/src/neighborly/plugins/talktown/spawn_tables.py b/src/neighborly/plugins/talktown/spawn_tables.py index 2f3cf5f..462210c 100644 --- a/src/neighborly/plugins/talktown/spawn_tables.py +++ b/src/neighborly/plugins/talktown/spawn_tables.py @@ -1,9 +1,6 @@ import pathlib -from typing import Any, Dict, List +from typing import Any -import yaml - -from neighborly.core.ecs import GameObjectFactory from neighborly.simulation import Neighborly, PluginInfo from neighborly.plugins.defaults.create_town import CreateDefaultSettlementSystem From 918aae6046824c7db8b424f4a39b96dbbc94ab2c Mon Sep 17 00:00:00 2001 From: Shi Johnson-Bey Date: Fri, 19 May 2023 21:19:42 -0700 Subject: [PATCH 2/3] tracery now seeded in Neighborly constructor --- src/neighborly/core/tracery.py | 11 +++++++++++ src/neighborly/simulation.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/neighborly/core/tracery.py b/src/neighborly/core/tracery.py index b393ab6..4bc17a0 100644 --- a/src/neighborly/core/tracery.py +++ b/src/neighborly/core/tracery.py @@ -17,6 +17,17 @@ class Tracery: _grammar: tracery.Grammar = tracery.Grammar({}) """The grammar instance.""" + @classmethod + def set_rng_seed(cls, seed: Union[int, str]) -> None: + """Set the seed for RNG used during rule evaluation. + + Parameters + ---------- + seed + An arbitrary seed value + """ + cls._grammar.rng.seed(seed) + @classmethod def add_rules(cls, rules: Dict[str, Union[str, List[str]]]) -> None: """Add grammar rules. diff --git a/src/neighborly/simulation.py b/src/neighborly/simulation.py index 9f05822..6571e10 100644 --- a/src/neighborly/simulation.py +++ b/src/neighborly/simulation.py @@ -10,6 +10,7 @@ import neighborly.components as components import neighborly.core.relationship as relationship +from neighborly.core.tracery import Tracery import neighborly.factories as factories import neighborly.systems as systems from neighborly.__version__ import VERSION @@ -94,6 +95,7 @@ def __init__(self, config: Optional[NeighborlyConfig] = None) -> None: # Seed RNG for libraries we don't control, like Tracery random.seed(self.config.seed) + Tracery.set_rng_seed(self.config.seed) # Set the relationship schema GameObjectFactory.add( From 34ace9b7a44f876449c29609d0b98c7c0deef3ce Mon Sep 17 00:00:00 2001 From: Shi Johnson-Bey Date: Fri, 19 May 2023 22:03:31 -0700 Subject: [PATCH 3/3] updated version number --- CHANGELOG.md | 6 ++++++ src/neighborly/__version__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce8dfcb..d278bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres mostly to [Semantic Versioning](https://semver.org/spec There may be minor-version updates that contain breaking changes, but do not warrant incrementing to a completely new version number. +## [0.11.1] + +### Fixes + +- The Tracery class is now seeded inside the Neighborly constructor + ## [0.11.0] **This update has breaking changes from version 0.10.x** diff --git a/src/neighborly/__version__.py b/src/neighborly/__version__.py index 056f0f4..b5ce99b 100644 --- a/src/neighborly/__version__.py +++ b/src/neighborly/__version__.py @@ -1 +1 @@ -VERSION = "0.11.0" +VERSION = "0.11.1"