Skip to content

Commit

Permalink
switch to json; put lines in center of squares for web app
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbenn committed Dec 31, 2018
1 parent e9dbd47 commit 0f27cd2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion gengo/app/static/js/board.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from browser import document, alert
from browser import websocket
import browser
import json
board_size = None


def on_message(evt):
# board = ast.literal_eval(evt.data)
# need to fix, but ast not loaded; should parse manually
board = eval(evt.data)
board = json.loads(evt.data)

for x in range(board_size):
for y in range(board_size):
Expand Down
10 changes: 7 additions & 3 deletions gengo/app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
type="text/python"></script>

<div id="rules" board_size={{board_size}}></div>
<svg width="500" height="500">
<svg width="750" height="750">
{% for x in range(board_size) %}
{% for y in range(board_size) %}
<rect id="{{'{},{}'.format(x,y)}}"
x="{{x*25}}" y="{{y*25}}"
height="25" width="25" fill="sandybrown", stroke="red"/>
x="{{x*30}}" y="{{y*30}}"
height="30" width="30" fill="sandybrown"/>
{% endfor %}
{% endfor %}
{% for x in range(board_size) %}
<line x1="15" x2="{{30*board_size-15}}" y1="{{15+x*30}}" y2="{{15+x*30}}" stroke="red"></line>
<line y1="15" y2="{{30*board_size-15}}" x1="{{15+x*30}}" x2="{{15+x*30}}" stroke="red"></line>
{% endfor %}
</svg>
</body>
</html>
Expand Down
5 changes: 4 additions & 1 deletion gengo/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
import websockets
import json
import ast

from ..src.gengo import Board, GridBoard, Rules, Player, Game, InvalidMove
Expand Down Expand Up @@ -38,7 +39,9 @@ async def start_game(websocket, path):
game = game.create_replay()
print(game)

response = str(game.board.colors())
response = json.dumps(game.board.colors())
print(f">json ({response})")
print(f">str ({str(game.board.colors())})")

await websocket.send(response)
print(f"> ({response})")
Expand Down
4 changes: 2 additions & 2 deletions gengo/src/gengo.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __iter__(self):
for i1 in range(self.size):
yield self[i0, i1]

def colors(self) -> str:
def colors(self) -> List[List[str]]:
'''Return list of lists of colors to paint on the server.
This will be replaced by...something else'''
empty_color = 'sandybrown' # type:str
Expand All @@ -183,7 +183,7 @@ def colors(self) -> str:
else:
row.append(overlap_color)
result.append(row)
return str(result)
return result

def __getitem__(self,
coords: Tuple[int, int]) -> "Space":
Expand Down

0 comments on commit 0f27cd2

Please sign in to comment.