add game end and fix cell removal code
This commit is contained in:
parent
baa492450f
commit
40e1c5a72c
|
@ -58,7 +58,12 @@ def update_loop():
|
||||||
|
|
||||||
if state["update_pause"] == 1:
|
if state["update_pause"] == 1:
|
||||||
state["update_emoji"] = "🍿"
|
state["update_emoji"] = "🍿"
|
||||||
if this_game.top_of_inning:
|
if this_game.over:
|
||||||
|
winning_team = this_game.teams['home'].name if this_game.teams['home'].score > this_game.teams['away'].score else this_game.teams['away'].name
|
||||||
|
state["update_text"] = f"{winning_team} wins{' with a victory lap' if state['victory_lap'] else ''}!"
|
||||||
|
state["pitcher"] = "-"
|
||||||
|
state["batter"] = "-"
|
||||||
|
elif this_game.top_of_inning:
|
||||||
state["update_text"] = f"Top of {this_game.inning}. {this_game.teams['away'].name} batting!"
|
state["update_text"] = f"Top of {this_game.inning}. {this_game.teams['away'].name} batting!"
|
||||||
else:
|
else:
|
||||||
if this_game.inning >= this_game.max_innings:
|
if this_game.inning >= this_game.max_innings:
|
||||||
|
@ -99,9 +104,13 @@ def update_loop():
|
||||||
states_to_send[game_time] = state
|
states_to_send[game_time] = state
|
||||||
|
|
||||||
if state["update_pause"] <= 1 and state["delay"] < 0:
|
if state["update_pause"] <= 1 and state["delay"] < 0:
|
||||||
this_game.gamestate_update_full()
|
if this_game.over:
|
||||||
|
master_games_dic.pop(game_time)
|
||||||
|
else:
|
||||||
|
this_game.gamestate_update_full()
|
||||||
|
|
||||||
state["update_pause"] -= 1
|
state["update_pause"] -= 1
|
||||||
|
|
||||||
global last_update
|
global last_update
|
||||||
last_update = states_to_send
|
last_update = states_to_send
|
||||||
socketio.emit("states_update", states_to_send)
|
socketio.emit("states_update", states_to_send)
|
||||||
|
|
|
@ -39,16 +39,30 @@ $(document).ready(function (){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var requiredcells = Math.max(4, (3 * Math.ceil(Object.keys(json).length/3))+1);
|
||||||
|
|
||||||
for (var slotnum = 1; slotnum < grid.children.length; slotnum++) {
|
for (var slotnum = 1; slotnum < grid.children.length; slotnum++) {
|
||||||
if (grid.children[slotnum].className == "game" && !(Object.keys(json).includes(grid.children[slotnum].timestamp))) {
|
if (grid.children[slotnum].className == "game" && !(Object.keys(json).includes(grid.children[slotnum].timestamp))) {
|
||||||
grid.removeChild(grid.children[slotnum]);
|
grid.removeChild(grid.children[slotnum]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while((grid.children.length - 1) % 3 != 0 || grid.children.length == 0) {
|
|
||||||
|
console.log(Object.keys(json).length)
|
||||||
|
console.log(requiredcells)
|
||||||
|
console.log(grid.children.length)
|
||||||
|
|
||||||
|
while (grid.children.length > requiredcells) {
|
||||||
|
grid.removeChild(grid.children[requiredcells]);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (grid.children.length < requiredcells) {
|
||||||
insertEmpty(grid);
|
insertEmpty(grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(grid.children.length)
|
||||||
});
|
});
|
||||||
|
|
||||||
const insertEmpty = (grid) => {
|
const insertEmpty = (grid) => {
|
||||||
newBox = document.createElement("DIV");
|
newBox = document.createElement("DIV");
|
||||||
newBox.className = "emptyslot";
|
newBox.className = "emptyslot";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user