Assigns teams to subscribers (used for Nov 2020 & Mar 2021) https://twitch.tv/bertiebaggio
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

teampicker.py 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/python3
  2. #
  3. # gamepicker.py - pick games for Novemeber 2020 sub crown
  4. #
  5. # Two files provided:
  6. # - subs.txt -- 8 subscribers
  7. # - teams.txt -- 26 teams
  8. #
  9. # Pseudocode:
  10. # Split screen in 1:3
  11. # - LHS = subscriber+team space
  12. # - RHS = teams space
  13. # Set BG image
  14. # Init seed
  15. # Lay out teams in order (3 cols)
  16. # On keypress, show subscriber name & show team random picker (via highlight)
  17. # Once picked, add subscriber + team to LHS
  18. import sys
  19. import random
  20. import pygame
  21. pygame.init()
  22. random.seed("BERTIE BEEF BAGGIO")
  23. SIZE = WIDTH, HEIGHT = 1920, 1080
  24. BGIMG = pygame.image.load("sub_crown_bg_2.png")
  25. FONT = pygame.font.SysFont("Fetamont", 50)
  26. SUBFONTHEIGHT = 35
  27. SUBFONT = pygame.font.SysFont("Fetamont", SUBFONTHEIGHT)
  28. OFFWHITE = (224, 224, 224)
  29. HIGHLIGHT = (255, 209, 0)
  30. BLUE = (20, 25, 153)
  31. PURPLE = (121, 35, 158)
  32. screen = pygame.display.set_mode(SIZE)
  33. # Set up team text positioning references
  34. #
  35. # 26 teams so 3 cols, 9 rows
  36. COLSTART = int(WIDTH/3)
  37. COLWIDTH = int((WIDTH-COLSTART)/3)
  38. ROWSTART = int(HEIGHT/12)
  39. ROWHEIGHT = int((HEIGHT-ROWSTART)/10)
  40. TEAMSFILE = "teams.txt"
  41. TEAMNUMCOLS = 3
  42. TEAMNUMROWS = 9
  43. TEAMCOLS = []
  44. TEAMROWS = []
  45. for i in range(TEAMNUMCOLS):
  46. print(COLSTART + i*COLWIDTH)
  47. TEAMCOLS.append(COLSTART + i*COLWIDTH)
  48. for i in range(TEAMNUMROWS):
  49. TEAMROWS.append(ROWSTART + i*ROWHEIGHT)
  50. print(ROWSTART + i*ROWHEIGHT)
  51. SUBSFILE = "subs.txt"
  52. SUBS = []
  53. SUBNUMROWS = 8
  54. SUBROWHEIGHT = int((HEIGHT-ROWSTART)/9)
  55. SUBROWS = []
  56. for i in range(SUBNUMROWS):
  57. SUBROWS.append(ROWSTART + i*SUBROWHEIGHT)
  58. TEAMS = [] # List of Team
  59. class Team(object):
  60. """Teams for iteration"""
  61. def __init__(self, team, x, y):
  62. self.team = team
  63. self.x = x
  64. self.y = y
  65. self.colour = OFFWHITE
  66. def highlight(self):
  67. self.colour = HIGHLIGHT
  68. def unhighlight(self):
  69. self.colour = OFFWHITE
  70. def draw(self):
  71. draw_text(self.team, FONT, self.colour, self.y, self.x)
  72. class Sub(object):
  73. """Like Team"""
  74. def __init__(self, sub):
  75. self.sub = sub
  76. self.team = ""
  77. self.x = 20
  78. self.y = 0
  79. def draw(self):
  80. draw_text(self.sub, SUBFONT, BLUE, self.x, self.y)
  81. if self.team != "":
  82. draw_text(self.team, SUBFONT, PURPLE,
  83. self.x, int(self.y+SUBFONTHEIGHT))
  84. def draw_text(text, font, text_col, x, y):
  85. img = font.render(text, True, text_col)
  86. screen.blit(img, (x, y))
  87. def setup_team_board():
  88. """Grab teams from text file and set their positions"""
  89. with open(TEAMSFILE, "r") as fh:
  90. for row in range(TEAMNUMROWS):
  91. for col in range(TEAMNUMCOLS):
  92. name = fh.readline().strip()
  93. if name == "":
  94. continue
  95. print("Adding {} at {},{}".format(name,
  96. TEAMCOLS[col],
  97. TEAMROWS[row]))
  98. TEAMS.append(Team(name,
  99. TEAMROWS[row], TEAMCOLS[col]))
  100. def setup_subs():
  101. """Check positioning, not actually used"""
  102. for i in range(len(SUBS)):
  103. # print("drawing {} at {},{}".format(SUBS[i], 20, SUBROWS[i]))
  104. SUBS[i].y = SUBROWS[i]
  105. # Prep
  106. for line in open(SUBSFILE, "r"):
  107. sub = line.strip()
  108. SUBS.append(Sub(sub))
  109. print(SUBS)
  110. random.shuffle(SUBS)
  111. setup_team_board()
  112. random.shuffle(TEAMS)
  113. setup_subs()
  114. while True:
  115. for event in pygame.event.get():
  116. if event.type == pygame.QUIT:
  117. sys.exit()
  118. elif event.type == pygame.KEYDOWN:
  119. if event.key == 113: # Q
  120. pygame.quit()
  121. sys.exit()
  122. elif event.key == 115:
  123. TEAMS[5].highlight()
  124. elif event.key == 32: # Spacebar
  125. for sub in SUBS:
  126. if sub.team == "":
  127. sub.team = TEAMS.pop().team
  128. elif event.key == 49:
  129. team = TEAMS.pop()
  130. SUBS[0].team = team.team
  131. elif event.key == 50:
  132. SUBS[1].team = TEAMS[random.randrange(len(TEAMS))].team
  133. print(event.key)
  134. screen.blit(BGIMG, (0, 0))
  135. for team in TEAMS:
  136. team.draw()
  137. for sub in SUBS:
  138. sub.draw()
  139. pygame.display.update()