From 8cb5d5a76c3ece810fe14f9146f095f34afa1ccf Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 28 Apr 2019 15:48:48 +1000 Subject: [PATCH] satisfactory: implement the 'resources' query --- describe.py | 3 ++- satisfactory/__init__.py | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/describe.py b/describe.py index b9cc3a3..1989616 100755 --- a/describe.py +++ b/describe.py @@ -9,5 +9,6 @@ if __name__ == '__main__': recipe_root = os.path.join(root, 'data', 'recipes') cookbook = satisfactory.Cookbook(recipe_root) - print(i for i in cookbook.resources()) + for i in cookbook.resources(): + print(i) diff --git a/satisfactory/__init__.py b/satisfactory/__init__.py index f5a4abc..348ccf1 100644 --- a/satisfactory/__init__.py +++ b/satisfactory/__init__.py @@ -26,19 +26,11 @@ class Cookbook(object): def is_component(self, name): return 'component' in self.__recipes[name]['type'] - def is_resource(self, name): - return '' - def components(self): - found = set() + return (i for i in self.all() if self.is_component(i)) - for _, descriptor in self.__recipes.items(): - for variation in descriptor['recipes']: - for need, _ in variation['input'].items(): - if need in found: - continue - found.add(need) - if not self.is_component(need): - continue - yield need + def is_resource(self, name): + return 'resource' in self.__recipes[name]['type'] + def resources(self): + return (i for i in self.all() if self.is_resource(i))