better node errors

This commit is contained in:
ntr 2018-12-30 17:44:29 +11:00
parent b92a88280f
commit f3eec0b0b1
3 changed files with 18 additions and 11 deletions

View File

@ -83,6 +83,15 @@ class MenuCrypList extends Phaser.Scene {
const CRYP_STATS = [cryp.stamina, cryp.phys_dmg, cryp.spell_dmg]; const CRYP_STATS = [cryp.stamina, cryp.phys_dmg, cryp.spell_dmg];
CRYP_STATS.forEach(crypStat); CRYP_STATS.forEach(crypStat);
const crypSkill = (skill, j) => {
const SKILL_X = ROW_X;
const SKILL_Y = ((j + 3) * TEXT_MARGIN) + ROW_Y + TEXT_MARGIN;
this.crypRows.add(this.add.text(SKILL_X, SKILL_Y, `${skill.skill}`, TEXT.NORMAL));
};
cryp.skills.forEach(crypSkill);
const selectBtn = this.add const selectBtn = this.add
.rectangle(0, ROW_Y + (ROW_HEIGHT * 0.9), ROW_WIDTH, ROW_HEIGHT / 10, FILL, 0.5) .rectangle(0, ROW_Y + (ROW_HEIGHT * 0.9), ROW_WIDTH, ROW_HEIGHT / 10, FILL, 0.5)
.setInteractive() .setInteractive()

View File

@ -12,9 +12,8 @@ strangle
## NOW ## NOW
* zones * zones
* differnt game types based on tag
* open w/ item? * open w/ item?
* close
* update on game finish
## SOON ## SOON
* aoe skills * aoe skills

View File

@ -141,9 +141,8 @@ pub fn zone_update(zone: &Zone, tx: &mut Transaction) -> Result<(), Error> {
pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> { pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let mut zone = zone_get(tx, params.zone_id)?; let mut zone = zone_get(tx, params.zone_id)?;
if !node_joinable(&zone.graph, NodeIndex::from(params.node_id)) { // check node joinable
return Err(err_msg("not not joinable")); node_joinable(&zone.graph, NodeIndex::from(params.node_id))?;
}
let mut game = game_pve_new(params.cryp_ids, PveMode::Normal, tx, account)?; let mut game = game_pve_new(params.cryp_ids, PveMode::Normal, tx, account)?;
game.set_zone(zone.id, params.node_id); game.set_zone(zone.id, params.node_id);
@ -197,7 +196,7 @@ pub fn create_zone_graph() -> ZoneGraph {
return gr; return gr;
} }
pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> bool { pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> Result<(), Error> {
// early return for already attempted // early return for already attempted
{ {
let target_encounter = match graph.node_weight(target_index) { let target_encounter = match graph.node_weight(target_index) {
@ -206,7 +205,7 @@ pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> bool {
}; };
if target_encounter.game_id.is_some() { if target_encounter.game_id.is_some() {
return false; return Err(err_msg("node already attempted"));
} }
} }
@ -222,12 +221,12 @@ pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> bool {
// it is joinable // it is joinable
for i in success_indices { for i in success_indices {
match graph.neighbors(i).find(|n| *n == target_index) { match graph.neighbors(i).find(|n| *n == target_index) {
Some(_n) => return true, Some(_n) => return Ok(()),
None => continue, None => continue,
}; };
} }
return false; return Err(err_msg("node requirements not met"));
} }
pub fn node_finish(game: &Game, zone_id: Uuid, node_index: u32, tx: &mut Transaction) -> Result<Zone, Error> { pub fn node_finish(game: &Game, zone_id: Uuid, node_index: u32, tx: &mut Transaction) -> Result<Zone, Error> {
@ -270,7 +269,7 @@ mod tests {
#[test] #[test]
fn zone_joinable_test() { fn zone_joinable_test() {
let graph = create_zone_graph(); let graph = create_zone_graph();
assert!(node_joinable(&graph, NodeIndex::from(1))); assert!(node_joinable(&graph, NodeIndex::from(1)).is_ok());
assert!(!node_joinable(&graph, NodeIndex::from(2))); assert!(node_joinable(&graph, NodeIndex::from(2)).is_err());
} }
} }