def test_sprixel_static_black(self): s = gfx_core.Sprixel.black_rect() self.assertEqual(s.model, " ") self.assertEqual(s.bg_color, gfx_core.Color(0, 0, 0)) s = gfx_core.Sprixel.black_square() self.assertEqual(s.model, " ") self.assertEqual(s.bg_color, gfx_core.Color(0, 0, 0))
def test_color_cmp(self): c1 = gfx_core.Color() c2 = gfx_core.Color() c3 = gfx_core.Color(1, 2, 3) self.assertEqual(c1, c2) self.assertNotEqual(c1, c3) self.assertFalse(c1 == c3) self.assertFalse(c1 != c2)
def test_text(self): text = pgl_base.Text( "Test case", core.Color(0, 0, 0), core.Color(255, 255, 0), pgl_base.Style.BRIGHT, ) t = pgl_base.Console.instance() self.assertEqual( text.__repr__(), "".join([ t.on_color_rgb(255, 255, 0), t.color_rgb(0, 0, 0), pgl_base.Style.BRIGHT, "Test case", "\x1b[0m", ]), ) self.assertIn("TEST", text.black("TEST")) self.assertIn("30m", text.black("TEST")) self.assertIn("TEST", text.red("TEST")) self.assertIn("31m", text.red("TEST")) self.assertIn("TEST", text.green("TEST")) self.assertIn("32m", text.green("TEST")) self.assertIn("TEST", text.yellow("TEST")) self.assertIn("33m", text.yellow("TEST")) self.assertIn("TEST", text.blue("TEST")) self.assertIn("34m", text.blue_bright("TEST")) self.assertIn("TEST", text.red_bright("TEST")) self.assertIn("TEST", text.green_bright("TEST")) self.assertIn("TEST", text.yellow_bright("TEST")) self.assertIn("TEST", text.magenta_bright("TEST")) self.assertIn("TEST", text.cyan_bright("TEST")) self.assertIn("TEST", text.white_bright("TEST")) self.assertIn("TEST", text.black_bright("TEST")) self.assertIn("TEST", text.magenta("TEST")) self.assertIn("TEST", text.cyan("TEST")) self.assertIn("TEST", text.white("TEST")) self.assertIn("TEST", text.red_dim("TEST")) self.assertIn("TEST", text.blue_dim("TEST")) self.assertIn("TEST", text.green_dim("TEST")) self.assertIn("TEST", text.yellow_dim("TEST")) self.assertIn("TEST", text.magenta_dim("TEST")) self.assertIn("TEST", text.cyan_dim("TEST")) self.assertIn("TEST", text.white_dim("TEST")) self.assertIn("TEST", text.black_dim("TEST")) self.assertIsNone(text.warn("test")) self.assertIsNone(text.fatal("test")) self.assertIsNone(text.info("test")) self.assertIsNone(text.debug("test")) self.assertIsNone(text.print_white_on_red("test")) with self.assertRaises(pgl_base.PglInvalidTypeException): pgl_base.Text("breaking", "pink") with self.assertRaises(pgl_base.PglInvalidTypeException): pgl_base.Text("breaking", None, "pink")
def test_item(self): self.board = pgl_engine.Board(name="test_board", size=[10, 10], player_starting_position=[5, 5]) self.placed_item = pgl_board_items.BoardItem() self.board.place_item(self.placed_item, 1, 1) self.returned_item = self.board.item(1, 1) self.assertEqual(self.placed_item, self.returned_item) with self.assertRaises( pgl_base.PglOutOfBoardBoundException) as excinfo: self.board.item(15, 15) self.assertTrue( "out of the board boundaries" in str(excinfo.exception)) sprix = gfx_core.Sprixel(bg_color=gfx_core.Color(45, 45, 45)) sprix.is_bg_transparent = True self.board.place_item( pgl_board_items.Door(sprixel=gfx_core.Sprixel( bg_color=gfx_core.Color(15, 15, 15))), 5, 5, ) i = pgl_board_items.NPC(sprixel=sprix) self.assertIsNone(self.board.place_item(i, 5, 5)) self.assertIsNone( self.board.place_item( pgl_board_items.ComplexNPC( base_item_type=pgl_board_items.Movable), 8, 8, 8, )) self.assertIsNone(self.board.place_item(pgl_board_items.Tile(), 8, 2)) with self.assertRaises(pgl_base.PglInvalidTypeException): self.board.place_item(1, 1, 1) with self.assertRaises(pgl_base.PglOutOfBoardBoundException): self.board.place_item(i, 100, 100) with self.assertRaises(pgl_base.PglInvalidTypeException): self.board.remove_item(1) # Let's try to break things j = pgl_board_items.NPC() j.store_position(2, 2) with self.assertRaises(pgl_base.PglException) as e: self.board.remove_item(j) self.assertEqual(e.exception.error, "invalid_item") self.assertTrue(self.board.remove_item(i)) b = pgl_engine.Board() i = pgl_board_items.ComplexNPC(sprite=gfx_core.Sprite( sprixels=[[gfx_core.Sprixel("#"), gfx_core.Sprixel("#")]])) self.assertIsNone(b.place_item(i, 5, 5, 0)) self.assertTrue(b.remove_item(i))
def test_color_create(self): color = gfx_core.Color() self.assertEqual(color.r, 0) self.assertEqual(color.g, 0) self.assertEqual(color.b, 0) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Color(False, 0, 0) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Color(0, False, 0) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Color(0, 0, False) self.assertEqual(color.__repr__(), "Color(0, 0, 0)")
def setUp(self): super().setUp() self.vectors = [] self.vectors.append(pgl_base.Vector2D()) self.vectors.append(pgl_base.Vector2D(1.0, 1.0)) self.vectors.append(pgl_base.Vector2D(2, 2)) self.text = pgl_base.Text( "Test case", core.Color(0, 0, 0), core.Color(255, 255, 0), pgl_base.Style.BRIGHT, ) self.math = pgl_base.Math()
def test_color_blend(self): c1 = gfx_core.Color(10, 10, 10) c2 = gfx_core.Color(20, 20, 20) c3 = c1.blend(c2) self.assertEqual(c3.r, 15) self.assertEqual(c3.g, 15) self.assertEqual(c3.b, 15) with self.assertRaises(gfx_core.base.PglInvalidTypeException): c1.blend(c2, 2) with self.assertRaises(gfx_core.base.PglInvalidTypeException): c1.blend(c2, "2.0") with self.assertRaises(gfx_core.base.PglInvalidTypeException): c1.blend("this is not going to work...")
def test_move_simple(self): def _act(p): setattr(p[0], "test_callback", True) p[0].assertEqual(p[1], 1) i = pgl_board_items.Player(sprixel=gfx_core.Sprixel("*")) i.sprixel.is_bg_transparent = True b = pgl_engine.Board( name="test_board", size=[10, 10], player_starting_position=[0, 0], ) b.place_item(i, 0, 0) self.assertIsNone(b.move(i, constants.DOWN, 1)) self.assertIsNone(b.move(i, constants.UP, 1)) self.assertIsNone(b.move(i, constants.RIGHT, 1)) self.assertIsNone(b.move(i, constants.LEFT, 1)) self.assertIsNone(b.move(i, constants.DRDOWN, 1)) self.assertIsNone(b.move(i, constants.DRUP, 1)) self.assertIsNone(b.move(i, constants.DLDOWN, 1)) self.assertIsNone(b.move(i, constants.DLUP, 1)) self.assertIsNone(b.move(i, pgl_base.Vector2D(0, 0))) self.assertEqual(i.pos, [0, 0, 0]) setattr(self, "test_callback", False) b.place_item( pgl_board_items.GenericActionableStructure( action=_act, action_parameters=[self, 1]), 0, 1, ) self.assertIsNone(b.move(i, constants.RIGHT, 1)) self.assertIsNone(b.move(i, constants.RIGHT, 1)) self.assertTrue(getattr(self, "test_callback")) b.place_item(pgl_board_items.Treasure(value=50), i.row + 1, i.column) self.assertIsNone(b.move(i, constants.DOWN, 1)) self.assertEqual(i.inventory.value(), 50) b.place_item( pgl_board_items.Door(sprixel=gfx_core.Sprixel( bg_color=gfx_core.Color(45, 45, 45))), i.row + 1, i.column, ) b.place_item( pgl_board_items.Door(sprixel=gfx_core.Sprixel( bg_color=gfx_core.Color(45, 45, 45))), i.row + 2, i.column, ) self.assertIsNone(b.move(i, constants.DOWN, 1)) self.assertIsNone(b.move(i, constants.DOWN, 1)) self.assertIsNone(b.clear_cell(i.row, i.column))
def test_sprixel_create(self): sprix = gfx_core.Sprixel() self.assertEqual(sprix.model, "") self.assertIsNone(sprix.bg_color) self.assertIsNone(sprix.fg_color) sprix = gfx_core.Sprixel("m", gfx_core.Color(0, 0, 0), gfx_core.Color(1, 1, 1)) self.assertEqual(sprix.model, "m") self.assertEqual(sprix.bg_color, gfx_core.Color(0, 0, 0)) self.assertEqual(sprix.fg_color, gfx_core.Color(1, 1, 1)) t = pgl_base.Console.instance() self.assertEqual( sprix.__repr__(), "".join([ t.on_color_rgb(0, 0, 0), t.color_rgb(1, 1, 1), "m", "\x1b[0m" ]), ) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Sprixel(False, gfx_core.Color(0, 0, 0), gfx_core.Color(1, 1, 1)) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Sprixel("False", "nope", gfx_core.Color(1, 1, 1)) with self.assertRaises(gfx_core.base.PglInvalidTypeException): gfx_core.Sprixel("False", gfx_core.Color(0, 0, 0), "nope") sprix = gfx_core.Sprixel(is_bg_transparent=True) self.assertTrue(sprix.is_bg_transparent)
def test_color_randomize(self): # Let's keep this simple: most often than not, # the randomized value should be different from the default one # and the previous one default_color = gfx_core.Color() c = gfx_core.Color() criteria_match_count = 0 total_rolls = 100 for i in range(total_rolls): previous_color = gfx_core.Color(c.r, c.g, c.b) c.randomize() if c != default_color and c != previous_color: criteria_match_count += 1 self.assertGreater(criteria_match_count, total_rolls // 2)
def test_create(self): p = particles.BaseParticle() self.assertEqual(p.type, "base_particle") self.assertEqual(p.size, [1, 1]) p = particles.BaseParticle( bg_color=core.Color(0, 0, 255), fg_color=core.Color(255, 0, 0), model="*", velocity=particles.base.Vector2D(), acceleration=particles.base.Vector2D(), lifespan=8, ) self.assertEqual(p.sprixel.bg_color, core.Color(0, 0, 255)) self.assertEqual(p.sprixel.fg_color, core.Color(255, 0, 0)) self.assertEqual(p.sprixel.model, "*")
def test_serialization(self): class Bork(pgl_board_items.Wall): def __init__(self, **kwargs): super().__init__(**kwargs) b = pgl_engine.Board(ui_board_void_cell_sprixel=gfx_core.Sprixel( " ", gfx_core.Color(0, 0, 0))) b.place_item(pgl_board_items.Wall(), 2, 2) b.place_item(TestItem(), 4, 4) data = b.serialize() self.assertIsNotNone(data) self.assertIsNone(pgl_engine.Board.load(None)) bl = pgl_engine.Board.load(data) self.assertEqual(b.player_starting_position, bl.player_starting_position) self.assertEqual(b.name, bl.name) self.assertEqual(b.ui_board_void_cell, bl.ui_board_void_cell) self.assertIsInstance(b.item(2, 2), pgl_board_items.Wall) self.assertEqual(b.item(2, 2).model, bl.item(2, 2).model) data["map_data"]["(2, 2, 0)"]["object"] = "<'=bork.bork'>" with self.assertRaises(SyntaxError): pgl_engine.Board.load(data) b.place_item(Bork(), 6, 6) with self.assertRaises(SyntaxError): pgl_engine.Board.load(b.serialize())
def test_glyph(self): font = core.Font("8bits") g = font.glyph("42") self.assertEqual(g, font.glyph("default")) g = font.glyph("a", core.Color(255, 0, 0)) self.assertIsInstance(g, core.Sprite) font = core.Font() self.assertIsNone(font.glyph("a"))
def test_complexnpc(self): sprite = gfx_core.Sprite( name="test_sprite", sprixels=[ [ gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), ] ], ) n = board_items.ComplexNPC(name="Test NPC", sprite=sprite) n.actuator = actuators.RandomActuator() data = n.serialize() self.assertEqual(n.name, data["name"]) self.assertEqual(n.sprite.name, data["sprite"]["name"]) n2 = board_items.ComplexNPC.load(data) self.assertEqual(n.name, n2.name)
def test_player(self): p = board_items.Player(inventory=board_items.engine.Inventory()) self.assertFalse(p.pickable()) self.assertTrue(p.has_inventory()) sprite = gfx_core.Sprite( name="test_sprite", sprixels=[ [ gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), gfx_core.Sprixel(" ", gfx_core.Color(255, 0, 0)), ] ], ) n = board_items.ComplexPlayer(name="Test Player", sprite=sprite) n.actuator = actuators.RandomActuator() data = n.serialize() self.assertEqual(n.name, data["name"]) self.assertEqual(n.sprite.name, data["sprite"]["name"]) n2 = board_items.ComplexPlayer.load(data) self.assertEqual(n.name, n2.name)
def test_color_update(self): color = gfx_core.Color() color.r = 1 self.assertEqual(color.r, 1) color.g = 1 self.assertEqual(color.g, 1) color.b = 1 self.assertEqual(color.b, 1) with self.assertRaises(gfx_core.base.PglInvalidTypeException): color.r = "1" with self.assertRaises(gfx_core.base.PglInvalidTypeException): color.g = "1" with self.assertRaises(gfx_core.base.PglInvalidTypeException): color.b = "1"
def test_colorpickers(self): conf = ui.UiConfig.instance(game=self.game) cpd = ui.ColorPickerDialog(config=conf) with self.assertRaises(pgl_base.PglInvalidTypeException): cpd.set_selection("42") self.assertEqual(cpd.title, "Pick a color") cpd.title = "Test" self.assertEqual(cpd.title, "Test") with self.assertRaises(pgl_base.PglInvalidTypeException): cpd.title = 42 cpd.set_color(core.Color(1, 2, 3)) cd = ui.ColorPicker(config=conf) self.assertEqual(cd.selection, 0) cd.selection = 1 self.assertEqual(cd.selection, 1) with self.assertRaises(pgl_base.PglInvalidTypeException): cd.selection = "42" self.assertIsInstance(cd.color, core.Color) with self.assertRaises(pgl_base.PglInvalidTypeException): cd.color = "42" cd.color = core.Color(4, 5, 6) self.assertEqual(cd.color.r, 4) self.assertEqual(cd.color.g, 5) self.assertEqual(cd.color.b, 6) self.assertEqual(cd.red, 4) self.assertEqual(cd.green, 5) self.assertEqual(cd.blue, 6) with self.assertRaises(pgl_base.PglInvalidTypeException): cd.red = "42" with self.assertRaises(pgl_base.PglInvalidTypeException): cd.green = "42" with self.assertRaises(pgl_base.PglInvalidTypeException): cd.blue = "42" self.game.screen.place(cpd, 0, 0) self.game.screen.update()
def test_menus(self): screen = self.game.screen conf = ui.UiConfig.instance(game=self.game) with self.assertRaises(pgl_base.PglInvalidTypeException): ui.MenuBar([42], config=conf) menubar = ui.MenuBar([ui.MenuAction("Default", fake_callback)], config=conf) with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.add_entry(42) menubar.spacing = 0 self.assertEqual(menubar.spacing, 0) with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.spacing = "42" menubar.config = conf self.assertIsInstance(menubar.config, ui.UiConfig) with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.config = "42" menubar.current_index = 0 self.assertEqual(menubar.current_index, 0) with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.current_index = "42" file_menu = ui.Menu( "File", [ ui.MenuAction("Open", fake_callback), ui.MenuAction(pgl_base.Text("Save"), fake_callback), ui.MenuAction("Save as", fake_callback), ui.MenuAction("Quit", fake_callback), ], config=conf, ) edit_menu = ui.Menu( pgl_base.Text("Edit", core.Color(0, 255, 255)), [ui.MenuAction("Copy", fake_callback)], ) menubar.add_entry(file_menu) menubar.add_entry(edit_menu) help_action = ui.MenuAction("Help", fake_callback) menubar.add_entry(help_action) with self.assertRaises(pgl_base.PglInvalidTypeException): ui.Menu(42) with self.assertRaises(pgl_base.PglInvalidTypeException): edit_menu.add_entry(42) edit_menu.add_entry(ui.MenuAction("Paste", fake_callback)) with self.assertRaises(pgl_base.PglInvalidTypeException): ui.Menu("42", ["this", "is", "not going to", "work"]) with self.assertRaises(pgl_base.PglInvalidTypeException): ui.MenuAction(42, fake_callback) with self.assertRaises(pgl_base.PglInvalidTypeException): ui.MenuAction("42", 42) edit_menu.title = "*E*dit" self.assertEqual(edit_menu.title.text, "*E*dit") edit_menu.title = pgl_base.Text("Edit") self.assertEqual(edit_menu.title.text, "Edit") with self.assertRaises(pgl_base.PglInvalidTypeException): edit_menu.title = 42 help_action.title = "Help (Shift+H)" self.assertEqual(help_action.title.text, "Help (Shift+H)") help_action.title = pgl_base.Text("Help") self.assertEqual(help_action.title.text, "Help") with self.assertRaises(pgl_base.PglInvalidTypeException): help_action.title = 42 help_action.action = fake_callback self.assertTrue(callable(help_action.action)) with self.assertRaises(pgl_base.PglInvalidTypeException): help_action.action = 42 with self.assertRaises(pgl_base.PglInvalidTypeException): help_action.config = 42 with self.assertRaises(pgl_base.PglInvalidTypeException): help_action.padding = "42" help_action.padding = 2 self.assertEqual(help_action.padding, 2) with self.assertRaises(pgl_base.PglInvalidTypeException): help_action.selected = 42 help_action.selected = True self.assertTrue(help_action.selected) edit_menu.padding = 0 self.assertEqual(edit_menu.padding, 0) with self.assertRaises(pgl_base.PglInvalidTypeException): edit_menu.padding = "42" with self.assertRaises(pgl_base.PglInvalidTypeException): edit_menu.config = "42" edit_menu.selected = True self.assertTrue(edit_menu.selected) with self.assertRaises(pgl_base.PglInvalidTypeException): edit_menu.selected = 42 export_menu = ui.Menu( "Export", [ ui.MenuAction("Sprite (.spr)", fake_callback), ui.MenuAction("PNG (.png)", fake_callback), ui.MenuAction("Animation as a GIF (.gif)", fake_callback), ], ) edit_menu.add_entry(export_menu) export_menu.selected = True self.assertTrue(export_menu.selected) self.assertTrue(type(export_menu.entries) is list) export_menu.entries = [ ui.MenuAction("Sprite (.spr)", fake_callback), ui.MenuAction("PNG (.png)", fake_callback), ui.MenuAction("Animation as a GIF (.gif)", fake_callback), ] self.assertEqual(len(export_menu.entries), 3) with self.assertRaises(pgl_base.PglInvalidTypeException): export_menu.entries = 42 with self.assertRaises(pgl_base.PglInvalidTypeException): export_menu.entries = [42] edit_menu.select_next() self.assertIsInstance(edit_menu.current_entry(), ui.MenuAction) edit_menu.select_previous() self.assertIsNone(edit_menu.current_entry()) menubar.select_next() entry = menubar.current_entry() self.assertTrue(entry.selected) menubar.current_index += 1 self.assertTrue(menubar.current_entry().selected) menubar.select_previous() self.assertTrue(menubar.current_entry().selected) self.assertTrue(type(menubar.length()) is int) menubar.close() self.assertEqual(menubar.current_index, -1) self.assertIsNone(edit_menu.expand()) # Screen update screen.place(menubar, 0, 0) screen.update() self.assertIsNone(edit_menu.collapse()) help_action.padding = 0 screen.force_update() menubar.entries = [ ui.MenuAction("Sprite (.spr)", fake_callback), ui.MenuAction("PNG (.png)", fake_callback), ui.MenuAction("Animation as a GIF (.gif)", fake_callback), ] with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.entries = 42 with self.assertRaises(pgl_base.PglInvalidTypeException): menubar.entries = [42]
def test_color(self): c = gfx_core.Color(1, 2, 3) self.assertEqual(c.r, 1) self.assertEqual(c.g, 2) self.assertEqual(c.b, 3)
print( base.Text.red_bright( "Your console/terminal needs to be at least 155 columns wide" f" to run that benchmark (current width is {g.screen.width})." ) ) exit() if g.screen.height < 65: print( base.Text.red_bright( "Your console/terminal needs to be at least 65 columns high" f" to run that benchmark (current height is {g.screen.height})." ) ) exit() g.player = board_items.Player(sprixel=core.Sprixel("@@", None, core.Color(0, 255, 255))) print("Loading resources: ", end="", flush=True) load_start = time.time() sprites = core.SpriteCollection.load_json_file("tests/pgl-benchmark.spr") panda = sprites["panda"] polus = sprites["Polus_Map"] load_stop = time.time() print("done") print("Generating Boards: ", end="", flush=True) gen_start = time.time() print("Benchmark Board ", end="", flush=True) g.load_board("hac-maps/benchmark.json", 1) print("[ok] ", end="", flush=True) g.change_level(1) print("High Definition Board ", end="", flush=True) polus_cam = board_items.Camera()
def test_tinting(self): sp = gfx_core.Sprite( sprixels=[ [ gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), ], [ gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), gfx_core.Sprixel( " ", gfx_core.Color(255, 255, 255), gfx_core.Color(255, 255, 255), ), ], ] ) spr = sp.tint(gfx_core.Color(0, 255, 0), 0.2) self.assertEqual(spr.sprixel(0, 0).bg_color.r, 204) self.assertEqual(spr.sprixel(0, 0).bg_color.g, 255) self.assertEqual(spr.sprixel(0, 0).bg_color.b, 204) # Original sprite should not be modified by tint self.assertEqual(sp.sprixel(0, 0).bg_color.r, 255) self.assertEqual(sp.sprixel(0, 0).bg_color.g, 255) self.assertEqual(sp.sprixel(0, 0).bg_color.b, 255) with self.assertRaises(gfx_core.base.PglInvalidTypeException): sp.tint(gfx_core.Color(0, 255, 0), 1.2) with self.assertRaises(gfx_core.base.PglInvalidTypeException): sp.tint(gfx_core.Color(0, 255, 0), -1.2) with self.assertRaises(gfx_core.base.PglInvalidTypeException): sp.modulate(gfx_core.Color(0, 255, 0), 1.2) with self.assertRaises(gfx_core.base.PglInvalidTypeException): sp.modulate(gfx_core.Color(0, 255, 0), -1.2) sp.modulate(gfx_core.Color(0, 255, 0), 0.2) # Original sprite should be modified by modulate self.assertEqual(sp.sprixel(0, 0).bg_color.r, 204) self.assertEqual(sp.sprixel(0, 0).bg_color.g, 255) self.assertEqual(sp.sprixel(0, 0).bg_color.b, 204)
print( base.Text.red_bright( "Your console/terminal needs to be at least 155 columns wide" f" to run that benchmark (current width is {g.screen.width})." ) ) exit() if g.screen.height < 65: print( base.Text.red_bright( "Your console/terminal needs to be at least 65 columns high" f" to run that benchmark (current height is {g.screen.height})." ) ) exit() g.player = board_items.Player(sprixel=core.Sprixel("@@", None, core.Color(0, 255, 255))) print("Loading resources: ", end="", flush=True) load_start = time.time() sprites = core.SpriteCollection.load_json_file("tests/pgl-benchmark.spr") panda = board_items.Camera() panda_frames = [sprites["panda"], sprites["panda2"]] panda_frame_idx = 0 polus = sprites["Polus_Map"] # p4ter = polus.scale(0.1) load_stop = time.time() print("done") print("Generating Boards: ", end="", flush=True) gen_start = time.time() print("Benchmark Board ", end="", flush=True) g.load_board("hac-maps/benchmark.json", 1)
def test_text(self): text = pgl_base.Text( "Test case", core.Color(0, 0, 0), core.Color(255, 255, 0), pgl_base.Style.BRIGHT, ) self.assertEqual(text.length, 9) t = pgl_base.Console.instance() self.assertEqual( text.__repr__(), "".join([ t.on_color_rgb(255, 255, 0), t.color_rgb(0, 0, 0), pgl_base.Style.BRIGHT, "Test case", "\x1b[0m", ]), ) self.assertEqual(text.__str__(), text.__repr__()) self.assertIn("TEST", text.black("TEST")) self.assertIn("30m", text.black("TEST")) self.assertIn("TEST", text.red("TEST")) self.assertIn("31m", text.red("TEST")) self.assertIn("TEST", text.green("TEST")) self.assertIn("32m", text.green("TEST")) self.assertIn("TEST", text.yellow("TEST")) self.assertIn("33m", text.yellow("TEST")) self.assertIn("TEST", text.blue("TEST")) self.assertIn("34m", text.blue_bright("TEST")) self.assertIn("TEST", text.red_bright("TEST")) self.assertIn("TEST", text.green_bright("TEST")) self.assertIn("TEST", text.yellow_bright("TEST")) self.assertIn("TEST", text.magenta_bright("TEST")) self.assertIn("TEST", text.cyan_bright("TEST")) self.assertIn("TEST", text.white_bright("TEST")) self.assertIn("TEST", text.black_bright("TEST")) self.assertIn("TEST", text.magenta("TEST")) self.assertIn("TEST", text.cyan("TEST")) self.assertIn("TEST", text.white("TEST")) self.assertIn("TEST", text.red_dim("TEST")) self.assertIn("TEST", text.blue_dim("TEST")) self.assertIn("TEST", text.green_dim("TEST")) self.assertIn("TEST", text.yellow_dim("TEST")) self.assertIn("TEST", text.magenta_dim("TEST")) self.assertIn("TEST", text.cyan_dim("TEST")) self.assertIn("TEST", text.white_dim("TEST")) self.assertIn("TEST", text.black_dim("TEST")) self.assertIsNone(text.warn("test")) self.assertIsNone(text.fatal("test")) self.assertIsNone(text.info("test")) self.assertIsNone(text.debug("test")) self.assertIsNone(text.print_white_on_red("test")) with self.assertRaises(pgl_base.PglInvalidTypeException): pgl_base.Text("breaking", "pink") with self.assertRaises(pgl_base.PglInvalidTypeException): pgl_base.Text("breaking", None, "pink") text.text = pgl_base.Text("Another test") self.assertEqual(text.text, "Another test") text.text = 12 self.assertEqual(text.text, "Another test") text.bg_color = core.Color(12, 34, 56) self.assertEqual(text.bg_color, core.Color(12, 34, 56)) with self.assertRaises(pgl_base.PglInvalidTypeException): text.bg_color = "pink" text.fg_color = core.Color(56, 78, 90) self.assertEqual(text.fg_color, core.Color(56, 78, 90)) with self.assertRaises(pgl_base.PglInvalidTypeException): text.fg_color = "definitely not pink! (because tests are not copy/pasted)" text.bg_color = None self.assertIsNone(text.bg_color) text.fg_color = None self.assertIsNone(text.fg_color) text = pgl_base.Text("This is a test", font=core.Font("8bits")) self.assertIsNone(text.be_notified(None)) self.assertIsInstance(text, pgl_base.Text) with self.assertRaises(pgl_base.PglInvalidTypeException): pgl_base.Text("This is a test", font=42) self.assertEqual(text.length, 126) text = pgl_base.Text( "Serialization test", core.Color(255, 0, 0), core.Color(0, 200, 200), "", font=core.Font("8bits"), ) text2 = pgl_base.Text.load(text.serialize()) self.assertEqual(text.text, text2.text) self.assertEqual(text.bg_color, text2.bg_color) self.assertEqual(text.fg_color, text2.fg_color) self.assertEqual(text.style, text2.style) text = pgl_base.Text("Serialization test", style=None) text2 = pgl_base.Text.load(text.serialize()) self.assertEqual(text.text, text2.text) self.assertEqual(text.bg_color, text2.bg_color) self.assertEqual(text.fg_color, text2.fg_color) self.assertEqual(text.style, None)