removed redux
This commit is contained in:
parent
24d7fa99c6
commit
9651f57a78
@ -1,29 +1,51 @@
|
|||||||
const actions = require('./actions');
|
function registerEvents(registry, events) {
|
||||||
|
function setCryps(cryps) {
|
||||||
|
console.log('setting cryps');
|
||||||
|
registry.set('cryps', cryps);
|
||||||
|
}
|
||||||
|
|
||||||
function registerEvents(store, registry, events) {
|
function setWs(ws) {
|
||||||
|
registry.set('ws', ws);
|
||||||
|
}
|
||||||
|
|
||||||
store.subscribe(() => {
|
function setGame(game) {
|
||||||
const state = store.getState();
|
registry.set('game', game);
|
||||||
registry.set('cryps', state.cryps);
|
}
|
||||||
registry.set('ws', state.ws);
|
|
||||||
registry.set('game', state.game);
|
|
||||||
registry.set('account', state.account);
|
|
||||||
});
|
|
||||||
|
|
||||||
events.on('CRYP_ACTIVE', (cryp) => {
|
function setAccount(account) {
|
||||||
const { cryps } = store.getState();
|
registry.set('account', account);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setItems(items) {
|
||||||
|
registry.set('items', items);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setGameList(gameList) {
|
||||||
|
registry.set('gameList', gameList);
|
||||||
|
}
|
||||||
|
|
||||||
|
events.on('CRYP_ACTIVE', function crypActiveCb(cryp) {
|
||||||
|
const cryps = registry.get('cryps');
|
||||||
|
|
||||||
cryps.forEach((c) => {
|
cryps.forEach((c) => {
|
||||||
if (c.id === cryp.id) {
|
if (c.id === cryp.id) {
|
||||||
console.log(c);
|
|
||||||
if (c.active) return c.active = false;
|
if (c.active) return c.active = false;
|
||||||
return c.active = true;
|
return c.active = true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
store.dispatch(actions.setCryps(cryps));
|
return setCryps(cryps);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
setAccount,
|
||||||
|
setCryps,
|
||||||
|
setGame,
|
||||||
|
setItems,
|
||||||
|
setWs,
|
||||||
|
setGameList,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = registerEvents;
|
module.exports = registerEvents;
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
const key = require('keymaster');
|
|
||||||
const actions = require('./actions');
|
|
||||||
|
|
||||||
function setupKeys(store) {
|
|
||||||
store.subscribe(() => {
|
|
||||||
const state = store.getState();
|
|
||||||
|
|
||||||
key.unbind('esc');
|
|
||||||
|
|
||||||
if (state.activeItem) {
|
|
||||||
key('esc', () => store.dispatch(actions.setActiveItem(null)));
|
|
||||||
}
|
|
||||||
if (state.activeSkill) {
|
|
||||||
key('esc', () => store.dispatch(actions.setActiveSkill(null)));
|
|
||||||
}
|
|
||||||
if (state.activeIncoming) {
|
|
||||||
key('esc', () => store.dispatch(actions.setActiveIncoming(null)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = setupKeys;
|
|
||||||
@ -1,34 +1,11 @@
|
|||||||
const { createStore, combineReducers } = require('redux');
|
|
||||||
|
|
||||||
const renderCryps = require('./scenes/cryps');
|
const renderCryps = require('./scenes/cryps');
|
||||||
|
|
||||||
const reducers = require('./reducers');
|
|
||||||
const actions = require('./actions');
|
|
||||||
const setupKeys = require('./keyboard');
|
|
||||||
const createSocket = require('./socket');
|
const createSocket = require('./socket');
|
||||||
const registerEvents = require('./events');
|
const registerEvents = require('./events');
|
||||||
|
|
||||||
// Redux Store
|
const game = renderCryps();
|
||||||
const store = createStore(
|
const events = registerEvents(game.registry, game.events);
|
||||||
combineReducers({
|
const ws = createSocket(events);
|
||||||
activeItem: reducers.activeItemReducer,
|
events.setWs(ws);
|
||||||
activeSkill: reducers.activeSkillReducer,
|
|
||||||
activeIncoming: reducers.activeIncomingReducer,
|
|
||||||
account: reducers.accountReducer,
|
|
||||||
game: reducers.gameReducer,
|
|
||||||
cryps: reducers.crypsReducer,
|
|
||||||
items: reducers.itemsReducer,
|
|
||||||
ws: reducers.wsReducer,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
store.subscribe(() => console.log(store.getState()));
|
|
||||||
setupKeys(store);
|
|
||||||
|
|
||||||
const ws = createSocket(store);
|
|
||||||
store.dispatch(actions.setWs(ws));
|
|
||||||
ws.connect();
|
ws.connect();
|
||||||
|
|
||||||
const game = renderCryps(store);
|
|
||||||
|
|
||||||
registerEvents(store, game.registry, game.events);
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class CrypList extends Phaser.Scene {
|
|||||||
|
|
||||||
create() {
|
create() {
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
|
this.registry.events.on('setdata', this.updateData, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,9 @@ const Menu = require('./menu');
|
|||||||
const Combat = require('./combat');
|
const Combat = require('./combat');
|
||||||
// const Passives = require('./passives');
|
// const Passives = require('./passives');
|
||||||
|
|
||||||
function renderCryps(store, socket) {
|
function renderCryps() {
|
||||||
const config = {
|
const config = {
|
||||||
type: Phaser.AUTO,
|
type: Phaser.AUTO,
|
||||||
// parent: 'cryps',
|
|
||||||
backgroundColor: '#181818',
|
backgroundColor: '#181818',
|
||||||
resolution: window.devicePixelRatio,
|
resolution: window.devicePixelRatio,
|
||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
const { toast } = require('bulma-toast');
|
const { toast } = require('bulma-toast');
|
||||||
const cbor = require('borc');
|
const cbor = require('borc');
|
||||||
|
|
||||||
const actions = require('./actions');
|
|
||||||
|
|
||||||
const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://cryps.gg/ws' : 'ws://localhost:40000';
|
const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://cryps.gg/ws' : 'ws://localhost:40000';
|
||||||
|
|
||||||
function errorToast(err) {
|
function errorToast(err) {
|
||||||
@ -17,7 +15,7 @@ function errorToast(err) {
|
|||||||
// Create WebSocket connection.
|
// Create WebSocket connection.
|
||||||
// requires the redux store in order to push updates
|
// requires the redux store in order to push updates
|
||||||
// to components
|
// to components
|
||||||
function createSocket(store) {
|
function createSocket(events) {
|
||||||
let ws;
|
let ws;
|
||||||
|
|
||||||
let gameStateTimeout;
|
let gameStateTimeout;
|
||||||
@ -77,7 +75,7 @@ function createSocket(store) {
|
|||||||
const [struct, login] = res;
|
const [struct, login] = res;
|
||||||
|
|
||||||
account = login;
|
account = login;
|
||||||
store.dispatch(actions.setAccount(login));
|
events.setAccount(login);
|
||||||
send({ method: 'account_cryps', params: {} });
|
send({ method: 'account_cryps', params: {} });
|
||||||
send({ method: 'item_list', params: {} });
|
send({ method: 'item_list', params: {} });
|
||||||
console.log(account);
|
console.log(account);
|
||||||
@ -85,21 +83,19 @@ function createSocket(store) {
|
|||||||
|
|
||||||
function accountCryps(response) {
|
function accountCryps(response) {
|
||||||
const [structName, cryps] = response;
|
const [structName, cryps] = response;
|
||||||
store.dispatch(actions.setCryps(cryps));
|
events.setCryps(cryps);
|
||||||
console.log('got my cryps', cryps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameState(response) {
|
function gameState(response) {
|
||||||
const [structName, game] = response;
|
const [structName, game] = response;
|
||||||
clearInterval(gameStateTimeout);
|
clearInterval(gameStateTimeout);
|
||||||
gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000);
|
gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000);
|
||||||
store.dispatch(actions.setGame(game));
|
events.setGame(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameJoinableList(response) {
|
function gameJoinableList(response) {
|
||||||
const [structName, gameList] = response;
|
const [structName, gameList] = response;
|
||||||
gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000);
|
events.setGameList(gameList);
|
||||||
store.dispatch(actions.setGame(game));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function crypSpawn(response) {
|
function crypSpawn(response) {
|
||||||
@ -114,7 +110,7 @@ function createSocket(store) {
|
|||||||
|
|
||||||
function itemList(response) {
|
function itemList(response) {
|
||||||
const [structName, items] = response;
|
const [structName, items] = response;
|
||||||
store.dispatch(actions.setItems(items));
|
events.setItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
@ -174,18 +170,18 @@ function createSocket(store) {
|
|||||||
game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, skill,
|
game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, skill,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
store.dispatch(actions.setActiveSkill(null));
|
events.setActiveSkill(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendGameTarget(gameId, crypId, skillId) {
|
function sendGameTarget(gameId, crypId, skillId) {
|
||||||
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, skill_id: skillId } });
|
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, skill_id: skillId } });
|
||||||
store.dispatch(actions.setActiveIncoming(null));
|
events.setActiveIncoming(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendItemUse(item, target) {
|
function sendItemUse(item, target) {
|
||||||
console.log(item, target);
|
console.log(item, target);
|
||||||
send({ method: 'item_use', params: { item, target } });
|
send({ method: 'item_use', params: { item, target } });
|
||||||
store.dispatch(actions.setActiveItem(null));
|
events.setActiveItem(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user