def clear_display(event=None): if DEBUG: print("Entering clear_display (mode={})".format(GAME_MODES[GAME_MODE])) global canvas try: document.getElementById("canvas").remove() except AttributeError: pass if DEBUG > 1: print("Destroying canvas with mode: {}".format(canvas.attrs["mode"])) canvas.deleteAll() # Create the base SVG object for the card table. canvas = SVG.CanvasObject("95vw", "95vh", None, objid="canvas") canvas.attrs["mode"] = GAME_MODES[GAME_MODE] # Attach the new canvas to the card_table div of the document. CardTable <= canvas canvas.setDimensions() update_display() # Update buttons canvas.addObject(button_clear) canvas.addObject(button_refresh) canvas.addObject(button_advance_mode) canvas.fitContents() canvas.mouseMode = SVG.MouseMode.DRAG
from browser import document import brySVG.dragcanvas as SVG canvas = SVG.CanvasObject("95vw", "100%", "cyan") document["demo1"] <= canvas tiles = [ SVG.ClosedBezierObject([((-100, 50), (50, 100), (200, 50)), ((-100, 50), (50, 0), (200, 50))]), SVG.GroupObject([ SVG.PolygonObject([(50, 25), (0, 50), (50, 75), (100, 50)]), SVG.SmoothBezierObject([(100, 0), (4, 40), (4, 60), (100, 100)]) ]), SVG.EllipseObject([(25, 0), (75, 100)], angle=30), SVG.GroupObject([ SVG.CircleObject((50, 50), 50), SVG.BezierObject([(None, (0, 100), (50, 25)), ((50, 25), (100, 100), None)]) ]), SVG.RectangleObject([(40, 0), (50, 90)], angle=20), SVG.GroupObject([ SVG.SmoothClosedBezierObject([(50, 5), (5, 80), (95, 80)]), SVG.PolylineObject([(0, 0), (30, 50), (70, 50), (100, 0)]) ]), ] for i in range(10): for j in range(6): tile = tiles[(i + j) % 6].cloneNode(True) #tile = tiles[(i+j)%6].cloneObject() #is slower but allows MouseMode.DRAG, TRANSFORM or EDIT to be used canvas <= tile
# "suit-club", # "suit-spade", # "suit-heart", # "suit-diamond", ] def calculate_dimensions(): global table_width, table_height # Gather information about the display environment table_width = document["canvas"].clientWidth table_height = document["canvas"].clientHeight # Create the base SVG object for the card table. canvas = SVG.CanvasObject("95vw", "95vh", "green", objid="canvas") # Intrinsic dimensions of the cards in the deck. card_width = 170 card_height = 245 # Gather information about the display environment table_width = document["card_table"].clientWidth table_height = document["card_table"].clientHeight # Calculate relative increments for the card table. xincr = int(table_width / 13) yincr = int(card_height / 4) # Where to start the first card on the table. (xpos, ypos) = (0, 0)
clear_display() # Make the update_display function easily available to scripts. window.update_display = update_display window.clear_display = clear_display window.advance_mode = advance_mode # Locate the card table in the HTML document. CardTable = document["card_table"] # Attach the card graphics file document["card_definitions"] <= SVG.Definitions(filename=CARD_URL) # Create the base SVG object for the card table. canvas = SVG.CanvasObject("95vw", "95vh", None, objid="canvas") canvas.attrs["mode"] = "initial" # TODO: Call game API to retrieve game_id, team_id, player_id, player names, etc... # TODO: Call game API to retrieve list of cards for player's hand and other sub-decks. # TODO: Add buttons & display to facilitate bidding. Tie into API. # Quickie deck generation while I'm building the real API pinochle_deck = list() for decks in range(0, 2): # Double deck for card in ["ace", "10", "king", "queen", "jack", "9"]: for suit in ["heart", "diamond", "spade", "club"]: pinochle_deck.append(f"{suit}_{card}") # Collect cards into discard, kitty and player's hand discard_deck = ["card-base" for _ in range(PLAYERS)]