diff --git a/client/src/components/cryp.list.container.js b/client/src/components/cryp.list.container.js
index 89f98009..5fcd16ba 100644
--- a/client/src/components/cryp.list.container.js
+++ b/client/src/components/cryp.list.container.js
@@ -5,8 +5,8 @@ const CrypList = require('./cryp.list');
const addState = connect(
function receiveState(state) {
const { ws, cryps, activeItem } = state;
- function sendCombatPve(crypId) {
- return ws.sendCombatPve(crypId);
+ function sendGamePve(crypId) {
+ return ws.sendGamePve(crypId);
}
function sendItemUse(targetId) {
@@ -16,7 +16,7 @@ const addState = connect(
return false;
}
- return { cryps, sendCombatPve, activeItem, sendItemUse };
+ return { cryps, sendGamePve, activeItem, sendItemUse };
}
);
diff --git a/client/src/components/cryp.list.jsx b/client/src/components/cryp.list.jsx
index 7795c2a1..cb718c45 100755
--- a/client/src/components/cryp.list.jsx
+++ b/client/src/components/cryp.list.jsx
@@ -3,7 +3,7 @@ const preact = require('preact');
const { stringSort } = require('./../utils');
const nameSort = stringSort('name');
-function CrypList({ cryps, activeItem, sendCombatPve, sendItemUse }) {
+function CrypList({ cryps, activeItem, sendGamePve, sendItemUse }) {
if (!cryps) return
...
;
- return (
-
-
{JSON.stringify(game)}
+
+ const otherTeams = game.teams.filter(t => t.id !== account.id);
+
+ const playerTeam = game.teams.find(t => t.id === account.id);
+ const playerCryps = playerTeam.cryps.map(c => (
+
+
{c.name}
+ ));
+
+
+ return (
+
+
+
them
+
{JSON.stringify(otherTeams)}
+
+
+
us
+ {playerCryps}
+
+
)
// return (
//
diff --git a/client/src/socket.jsx b/client/src/socket.jsx
index 4d89b0b1..357fd547 100755
--- a/client/src/socket.jsx
+++ b/client/src/socket.jsx
@@ -24,7 +24,7 @@ function createSocket(store) {
// Connection opened
ws.addEventListener('open', function wsOpen(event) {
- //send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
+ send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
});
// Listen for messages
@@ -79,7 +79,7 @@ function createSocket(store) {
console.log('got a new cryp', cryp);
}
- function combatPve(response) {
+ function gamePve(response) {
const [structName, game] = response;
console.log('got a new game', game);
}
@@ -109,10 +109,15 @@ function createSocket(store) {
send({ method: 'cryp_spawn', params: { name } });
}
- function sendCombatPve(id) {
- send({ method: 'combat_pve', params: { id } });
+ function sendGamePve(id) {
+ send({ method: 'game_pve', params: { id } });
}
+ function sendGameAbility(gameId, crypId, targetTeamId, ability) {
+ send({ method: 'game_ability', params: { game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, ability } });
+ }
+
+
function sendItemUse(item, target) {
console.log(item, target);
send({ method: 'item_use', params: { item, target } });
@@ -127,7 +132,7 @@ function createSocket(store) {
// this object wraps the reply types to a function
const handlers = {
cryp_spawn: crypSpawn,
- combat_pve: combatPve,
+ game_pve: gamePve,
game_state: gameState,
account_login: accountLogin,
account_create: accountLogin,
@@ -153,7 +158,8 @@ function createSocket(store) {
return {
sendAccountLogin,
sendAccountRegister,
- sendCombatPve,
+ sendGamePve,
+ sendGameAbility,
sendCrypSpawn,
sendItemUse,
connect,
diff --git a/ops/migrations/20181020104420_games.js b/ops/migrations/20181020104420_games.js
index b31fb6b8..2704e2bb 100644
--- a/ops/migrations/20181020104420_games.js
+++ b/ops/migrations/20181020104420_games.js
@@ -1,12 +1,13 @@
exports.up = async knex => {
- knex.schema.createTable('games', table => {
+ await knex.schema.createTable('games', table => {
table.uuid('id').primary();
- table.timestamps();
- table.binary('data').notNullable();
table.index('id');
+ table.timestamps();
+
+ table.binary('data').notNullable();
});
- knex.schema.createTable('players', table => {
+ await knex.schema.createTable('players', table => {
table.uuid('id').primary();
table.index('id');
diff --git a/server/src/game.rs b/server/src/game.rs
index 0d274add..30c2f500 100755
--- a/server/src/game.rs
+++ b/server/src/game.rs
@@ -363,12 +363,12 @@ pub fn game_new(game: Game, tx: &mut Transaction) -> Result {
let query = "
INSERT INTO games (id, data)
- VALUES ($1, $2, $3)
- RETURNING id, account;
+ VALUES ($1, $2)
+ RETURNING id;
";
let result = tx
- .query(query, &[&game_bytes, &game.id])?;
+ .query(query, &[&game.id, &game_bytes])?;
let _returned = result.iter().next().expect("no row returned");
@@ -377,6 +377,34 @@ pub fn game_new(game: Game, tx: &mut Transaction) -> Result {
return Ok(game);
}
+pub fn players_write(game: Game, tx: &mut Transaction) -> Result {
+ let game_bytes = to_vec(&game)?;
+
+ for team in &game.teams {
+ // pve
+ if !team.id.is_nil() {
+ for cryp in &team.cryps {
+ let id = Uuid::new_v4();
+
+ let query = "
+ INSERT INTO players (id, game, cryp, account)
+ VALUES ($1, $2, $3, $4)
+ RETURNING id, account;
+ ";
+
+ let result = tx
+ .query(query, &[&id, &game.id, &cryp.id, &team.id])?;
+
+ let _returned = result.iter().next().expect("no row written");
+
+ println!("wrote player entry game:{:?} cryp:{:?} account:{:?}", game.id, cryp.id, team.id);
+ }
+ }
+ }
+
+ return Ok(game);
+}
+
pub fn game_write(game: Game, tx: &mut Transaction) -> Result {
let game_bytes = to_vec(&game)?;
@@ -390,7 +418,7 @@ pub fn game_write(game: Game, tx: &mut Transaction) -> Result {
let result = tx
.query(query, &[&game_bytes, &game.id])?;
- let _returned = result.iter().next().expect("no row returned");
+ let returned = result.iter().next().expect("no row returned");
println!("{:?} wrote game", game.id);
@@ -461,7 +489,7 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
game.start();
- Ok(game)
+ return game_new(game, tx);
}
#[cfg(test)]