def run(self): start_time = datetime.datetime.now() logger = ConsoleLogger() logger.log('Started') cache_dir_path = os.path.abspath('./soe/cached_data') logger.log('Cache path: ' + cache_dir_path) data_provider = CachedDataProvider(SonyDataProvider(UrlReader(logger)), FileDataCache(cache_dir_path)) spell_effect_formatter = SpellEffectFormatter() coord_mapper = AACoordMapper() aa_factory = AAFactory(data_provider, spell_effect_formatter, coord_mapper, logger) tree_factory = TreeFactory(data_provider, aa_factory, logger) point_pool_factory = PointPoolFactory() class_factory = EQ2ClassFactory(data_provider, tree_factory, point_pool_factory, logger) json_writer = JsonFileWriter(logger) build_dir = os.path.abspath('../../build') icon_output_path = os.path.join(build_dir, 'icons') self._ensure_dir_exists(icon_output_path) icon_downloader = IconDownloader(data_provider, icon_output_path, logger) image_manipulator = ImageManipulator() sprite_output_path = os.path.join(build_dir, 'sprites') self._ensure_dir_exists(sprite_output_path) sprite_image_generator = SpriteImageGenerator(image_manipulator, icon_output_path, sprite_output_path, logger) classes = list(class_factory.create_classes()) tree_output_dir = os.path.join('.', 'output') tree_minified_output_dir = os.path.join('.', 'output_min') icon_size = 42 icon_padding = 1 sprite_css_generator = SpriteCssGenerator() for c in classes: icon_downloader.download_all(c) sprite_image_generator.generate(c, icon_size, icon_padding) filename = c.name + '.json' json_writer.write(c.to_dict(), os.path.join(tree_output_dir, filename), indent=3) json_writer.write(c.to_dict(), os.path.join(tree_minified_output_dir, filename)) if c.name == 'Beastlord': beastlord_css = sprite_css_generator.generate_css(c.trees, icon_size, icon_padding, '.Beastlord ') self._write_to_text_file(os.path.join(sprite_output_path, "sprites-beastlord.css"), beastlord_css) css = sprite_css_generator.generate_css(classes[0].trees, icon_size, icon_padding) self._write_to_text_file(os.path.join(sprite_output_path, "sprites.css"), css) end_time = datetime.datetime.now() logger.log('Done in {0}'.format(end_time - start_time))
def setUp(self): self._icon_size = 10 self._padding = 1 self.sut = SpriteCssGenerator()
class TestSpriteCssgenerator(unittest.TestCase): def setUp(self): self._icon_size = 10 self._padding = 1 self.sut = SpriteCssGenerator() def test_generate_css_single_tree(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Archetype" result = self.sut.generate_css([tree1], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual( lines[0], ".Archetype .aa.id0 .icon { background-position: -1px -1px; }") self.assertEqual( lines[1], ".Archetype .aa.id1 .icon { background-position: -13px -1px; }") self.assertEqual( lines[2], ".Archetype .aa.id2 .icon { background-position: -25px -1px; }") def test_generate_css_two_trees(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Archetype" tree2 = MagicMock() tree2.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree2.type = "Shadows" result = self.sut.generate_css([tree1, tree2], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual( lines[0], ".Archetype .aa.id0 .icon { background-position: -1px -1px; }") self.assertEqual( lines[1], ".Archetype .aa.id1 .icon { background-position: -13px -1px; }") self.assertEqual( lines[2], ".Archetype .aa.id2 .icon { background-position: -25px -1px; }") self.assertEqual( lines[3], ".Shadows .aa.id0 .icon { background-position: -1px -13px; }") self.assertEqual( lines[4], ".Shadows .aa.id1 .icon { background-position: -13px -13px; }") self.assertEqual( lines[5], ".Shadows .aa.id2 .icon { background-position: -25px -13px; }") def test_generate_css_warder_tree_has_additional_selector(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Warder" tree1.name = 'War Boar' result = self.sut.generate_css([tree1], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual( lines[0], ".Warder.WarBoar .aa.id0 .icon { background-position: -1px -1px; }" ) self.assertEqual( lines[1], ".Warder.WarBoar .aa.id1 .icon { background-position: -13px -1px; }" ) self.assertEqual( lines[2], ".Warder.WarBoar .aa.id2 .icon { background-position: -25px -1px; }" ) def test_generate_css_selector_prefix_is_prepended(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0)] tree1.type = "Archetype" result = self.sut.generate_css([tree1], self._icon_size, self._padding, 'Prefix') lines = result.split(os.linesep) self.assertEqual( lines[0], "Prefix.Archetype .aa.id0 .icon { background-position: -1px -1px; }" ) def _create_aa(self, id_): result = MagicMock() result.id = id_ return result
def run(self): start_time = datetime.datetime.now() logger = ConsoleLogger() logger.log('Started') cache_dir_path = os.path.abspath('./soe/cached_data') logger.log('Cache path: ' + cache_dir_path) data_provider = CachedDataProvider(SonyDataProvider(UrlReader(logger)), FileDataCache(cache_dir_path)) spell_effect_formatter = SpellEffectFormatter() coord_mapper = AACoordMapper() aa_factory = AAFactory(data_provider, spell_effect_formatter, coord_mapper, logger) tree_factory = TreeFactory(data_provider, aa_factory, logger) point_pool_factory = PointPoolFactory() class_factory = EQ2ClassFactory(data_provider, tree_factory, point_pool_factory, logger) json_writer = JsonFileWriter(logger) build_dir = os.path.abspath('../../build') icon_output_path = os.path.join(build_dir, 'icons') self._ensure_dir_exists(icon_output_path) icon_downloader = IconDownloader(data_provider, icon_output_path, logger) image_manipulator = ImageManipulator() sprite_output_path = os.path.join(build_dir, 'sprites') self._ensure_dir_exists(sprite_output_path) sprite_image_generator = SpriteImageGenerator(image_manipulator, icon_output_path, sprite_output_path, logger) classes = list(class_factory.create_classes()) tree_output_dir = os.path.join('.', 'output') tree_minified_output_dir = os.path.join('.', 'output_min') icon_size = 42 icon_padding = 1 sprite_css_generator = SpriteCssGenerator() for c in classes: icon_downloader.download_all(c) sprite_image_generator.generate(c, icon_size, icon_padding) filename = c.name + '.json' json_writer.write(c.to_dict(), os.path.join(tree_output_dir, filename), indent=3) json_writer.write(c.to_dict(), os.path.join(tree_minified_output_dir, filename)) if c.name == 'Beastlord': beastlord_css = sprite_css_generator.generate_css( c.trees, icon_size, icon_padding, '.Beastlord ') self._write_to_text_file( os.path.join(sprite_output_path, "sprites-beastlord.css"), beastlord_css) css = sprite_css_generator.generate_css(classes[0].trees, icon_size, icon_padding) self._write_to_text_file( os.path.join(sprite_output_path, "sprites.css"), css) end_time = datetime.datetime.now() logger.log('Done in {0}'.format(end_time - start_time))
def setUp(self): self._icon_size = 10 self._padding = 1 self.sut = SpriteCssGenerator()
class TestSpriteCssgenerator(unittest.TestCase): def setUp(self): self._icon_size = 10 self._padding = 1 self.sut = SpriteCssGenerator() def test_generate_css_single_tree(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Archetype" result = self.sut.generate_css([tree1], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual(lines[0], ".Archetype .aa.id0 .icon { background-position: -1px -1px; }") self.assertEqual(lines[1], ".Archetype .aa.id1 .icon { background-position: -13px -1px; }") self.assertEqual(lines[2], ".Archetype .aa.id2 .icon { background-position: -25px -1px; }") def test_generate_css_two_trees(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Archetype" tree2 = MagicMock() tree2.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree2.type = "Shadows" result = self.sut.generate_css([tree1, tree2], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual(lines[0], ".Archetype .aa.id0 .icon { background-position: -1px -1px; }") self.assertEqual(lines[1], ".Archetype .aa.id1 .icon { background-position: -13px -1px; }") self.assertEqual(lines[2], ".Archetype .aa.id2 .icon { background-position: -25px -1px; }") self.assertEqual(lines[3], ".Shadows .aa.id0 .icon { background-position: -1px -13px; }") self.assertEqual(lines[4], ".Shadows .aa.id1 .icon { background-position: -13px -13px; }") self.assertEqual(lines[5], ".Shadows .aa.id2 .icon { background-position: -25px -13px; }") def test_generate_css_warder_tree_has_additional_selector(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)] tree1.type = "Warder" tree1.name = 'War Boar' result = self.sut.generate_css([tree1], self._icon_size, self._padding) lines = result.split(os.linesep) self.assertEqual(lines[0], ".Warder.WarBoar .aa.id0 .icon { background-position: -1px -1px; }") self.assertEqual(lines[1], ".Warder.WarBoar .aa.id1 .icon { background-position: -13px -1px; }") self.assertEqual(lines[2], ".Warder.WarBoar .aa.id2 .icon { background-position: -25px -1px; }") def test_generate_css_selector_prefix_is_prepended(self): tree1 = MagicMock() tree1.aa = [self._create_aa(0)] tree1.type = "Archetype" result = self.sut.generate_css([tree1], self._icon_size, self._padding, 'Prefix') lines = result.split(os.linesep) self.assertEqual(lines[0], "Prefix.Archetype .aa.id0 .icon { background-position: -1px -1px; }") def _create_aa(self, id_): result = MagicMock() result.id = id_ return result