Merge branch 'develop' of ssh://git.mnml.gg:40022/~/mnml into develop

This commit is contained in:
ntr 2019-09-09 16:46:48 +10:00
commit 5874f040ad
5 changed files with 50 additions and 6 deletions

View File

@ -23,8 +23,13 @@ const addState = connect(
return ws.sendInstanceState(game.instance); return ws.sendInstanceState(game.instance);
} }
function sendGameSkillClear() {
return ws.sendGameSkillClear(game.id);
}
return { return {
game, game,
sendGameSkillClear,
sendReady, sendReady,
account, account,
getInstanceState, getInstanceState,
@ -48,9 +53,10 @@ function Controls(args) {
account, account,
game, game,
animating, animating,
sendGameSkillClear,
sendReady, sendReady,
quit,
getInstanceState, getInstanceState,
quit,
} = args; } = args;
if (!game) return false; if (!game) return false;
@ -98,7 +104,7 @@ function Controls(args) {
<div class="controls"> <div class="controls">
<PlayerBox player={opponent}/> <PlayerBox player={opponent}/>
{game.phase === 'Finish' ? quitBtn : readyBtn} {game.phase === 'Finish' ? quitBtn : readyBtn}
<PlayerBox player={player} isPlayer={true}/> <PlayerBox player={player} isPlayer={true} isGame={true} clear={sendGameSkillClear}/>
</div> </div>
</aside> </aside>
); );

View File

@ -3,9 +3,9 @@ const preact = require('preact');
function Scoreboard(args) { function Scoreboard(args) {
const { const {
isPlayer, isPlayer,
ready,
player, player,
isGame,
clear,
leave, leave,
} = args; } = args;
@ -37,7 +37,10 @@ function Scoreboard(args) {
<div class="img"> <div class="img">
<div>{player.name}</div> <div>{player.name}</div>
</div> </div>
<div class="ctrl"> <div>
{(isPlayer && isGame) ? <button onClick={clear}>Clear</button> : null}
</div>
<div>
{leave ? <button onClick={leave}>Leave</button> : null} {leave ? <button onClick={leave}>Leave</button> : null}
</div> </div>
</div> </div>

View File

@ -108,6 +108,11 @@ function createSocket(events) {
events.setActiveSkill(null); events.setActiveSkill(null);
} }
function sendGameSkillClear(gameId) {
send(['GameSkillClear', { game_id: gameId }]);
events.setActiveSkill(null);
}
function sendGameTarget(gameId, constructId, skillId) { function sendGameTarget(gameId, constructId, skillId) {
send(['GameTarget', { game_id: gameId, construct_id: constructId, skill_id: skillId }]); send(['GameTarget', { game_id: gameId, construct_id: constructId, skill_id: skillId }]);
events.setActiveSkill(null); events.setActiveSkill(null);
@ -316,6 +321,7 @@ function createSocket(events) {
sendGameState, sendGameState,
sendGameReady, sendGameReady,
sendGameSkill, sendGameSkill,
sendGameSkillClear,
sendGameTarget, sendGameTarget,
sendInstanceReady, sendInstanceReady,

View File

@ -322,6 +322,17 @@ impl Game {
return Ok(self); return Ok(self);
} }
fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
self.player_by_id(player_id)?;
if self.phase != Phase::Skill {
return Err(err_msg("game not in skill phase"));
}
let mut game_state = self.clone();
self.stack.retain(|s| game_state.construct_by_id(s.source_construct_id).unwrap().account == player_id);
return Ok(self);
}
fn player_ready(&mut self, player_id: Uuid) -> Result<&mut Game, Error> { fn player_ready(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
if self.phase != Phase::Skill { if self.phase != Phase::Skill {
return Err(err_msg("game not in skill phase")); return Err(err_msg("game not in skill phase"));
@ -877,6 +888,20 @@ pub fn game_skill(tx: &mut Transaction, account: &Account, game_id: Uuid, constr
Ok(game) Ok(game)
} }
pub fn game_skill_clear(tx: &mut Transaction, account: &Account, game_id: Uuid) -> Result<Game, Error> {
let mut game = game_get(tx, game_id)?;
game.clear_skill(account.id)?;
if game.skill_phase_finished() {
game = game.resolve_phase_start();
}
game_update(tx, &game)?;
Ok(game)
}
pub fn game_ready(tx: &mut Transaction, account: &Account, id: Uuid) -> Result<Game, Error> { pub fn game_ready(tx: &mut Transaction, account: &Account, id: Uuid) -> Result<Game, Error> {
let mut game = game_get(tx, id)?; let mut game = game_get(tx, id)?;

View File

@ -20,7 +20,7 @@ use account::{Account};
use account; use account;
use construct::{Construct}; use construct::{Construct};
use events::{Event}; use events::{Event};
use game::{Game, game_state, game_skill, game_ready}; use game::{Game, game_state, game_skill, game_skill_clear, game_ready};
use instance::{Instance, instance_state, instance_practice, instance_ready}; use instance::{Instance, instance_state, instance_practice, instance_ready};
use item::{Item, ItemInfoCtr, item_info}; use item::{Item, ItemInfoCtr, item_info};
use mtx; use mtx;
@ -75,6 +75,7 @@ enum RpcRequest {
GameState { id: Uuid }, GameState { id: Uuid },
GameReady { id: Uuid }, GameReady { id: Uuid },
GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill }, GameSkill { game_id: Uuid, construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill },
GameSkillClear { game_id: Uuid },
AccountState {}, AccountState {},
AccountShop {}, AccountShop {},
@ -169,6 +170,9 @@ impl Connection {
RpcRequest::GameSkill { game_id, construct_id, target_construct_id, skill } => RpcRequest::GameSkill { game_id, construct_id, target_construct_id, skill } =>
Ok(RpcMessage::GameState(game_skill(&mut tx, account, game_id, construct_id, target_construct_id, skill)?)), Ok(RpcMessage::GameState(game_skill(&mut tx, account, game_id, construct_id, target_construct_id, skill)?)),
RpcRequest::GameSkillClear { game_id } =>
Ok(RpcMessage::GameState(game_skill_clear(&mut tx, account, game_id)?)),
RpcRequest::GameReady { id } => RpcRequest::GameReady { id } =>
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)), Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),