def test_create_animation(self): self.item = pgl_board_items.NPC(model="-o-", name="Dancer") self.animation = gfx_core.Animation(parent=self.item, refresh_screen=self.redraw, display_time=0.5) self.assertEqual(self.item.name, self.animation.parent.name) a = gfx_core.Animation( animated_object=self.item, refresh_screen=self.redraw, display_time=0.5, initial_index=2, ) self.assertEqual(a._initial_index, 2) a.reset() self.assertEqual(a._initial_index, a._frame_index) col = gfx_core.SpriteCollection() col.add(gfx_core.Sprite(name="s1")) col.add(gfx_core.Sprite(name="s2")) i = pgl_board_items.ComplexNPC(sprite=col["s1"]) a = gfx_core.Animation(frames=col, parent=i) i.animation = a self.assertIsInstance(a, gfx_core.Animation) self.assertEqual(len(a.frames), 2) # I shouldn't test that here but I'm tired of writting test! self.assertIsInstance(a.next_frame(), gfx_core.Sprite)
def test_collection(self): spr = gfx_core.Sprite( sprixels=[ [ gfx_core.Sprixel.cyan_rect(), gfx_core.Sprixel.red_rect(), gfx_core.Sprixel.green_rect(), ], [ gfx_core.Sprixel.yellow_rect(), gfx_core.Sprixel.blue_rect(), gfx_core.Sprixel.white_rect(), ], ] ) spr2 = spr.flip_horizontally() spr3 = spr.flip_vertically() sc = gfx_core.SpriteCollection() sc.add(spr) sc.add(spr2) sc.add(spr3) with self.assertRaises(gfx_core.base.PglInvalidTypeException): sc.add(1) self.assertEqual(spr.name, sc[spr.name].name) self.assertEqual(spr.name, sc.get(spr.name).name) self.assertEqual(spr2.name, sc[spr2.name].name) self.assertEqual(spr2.name, sc.get(spr2.name).name) self.assertEqual(spr3.name, sc[spr3.name].name) self.assertEqual(spr3.name, sc.get(spr3.name).name) self.assertIsNone(sc.rename(spr.name, "test_rename")) self.assertEqual(sc["test_rename"].sprixel(0, 0), spr.sprixel(0, 0)) self.assertIsNone(sc.to_json_file("test.pgs")) sc2 = gfx_core.SpriteCollection.load_json_file("test.pgs") self.assertIsInstance(sc2, gfx_core.SpriteCollection) self.assertEqual(spr3.sprixel(1, 1), sc2.get(spr3.name).sprixel(1, 1)) with self.assertRaises(gfx_core.base.PglException) as e: gfx_core.SpriteCollection.load({}) self.assertEqual(e.exception.error, "invalid_sprite_data") with self.assertRaises(gfx_core.base.PglException) as e: gfx_core.SpriteCollection.load({"sprites_count": 2, "sprites": {}}) self.assertEqual(e.exception.error, "corrupted_sprite_data")
) output = climage.to_file( file, tmp_file, is_unicode=config["is_unicode"], is_truecolor=config["is_truecolor"], is_256color=config["is_256color"], is_16color=config["is_16color"], is_8color=config["is_8color"], width=width, palette="default", ) not args.silent and print(base.Text.blue("done"), flush=True) sc = core.SpriteCollection() final = os.path.join(output_dir, spr_id + ".spr") if args.collection != "": if os.path.exists(args.collection): not args.silent and print( f"Loading collection: {base.Text.blue(args.collection)}...", end="", flush=True, ) sc = sc.load_json_file(args.collection) not args.silent and print(base.Text.blue("done"), flush=True) final = args.collection not args.silent and print( "Converting ANSI sequence to Sprite...", end="", flush=True) spr = core.Sprite.load_from_ansi_file(tmp_file) not args.silent and print(base.Text.blue("done"), flush=True)