Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardcore/client

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardcore/client - npm Package Compare versions

Comparing version 0.0.1-e610b5ce to 0.0.1-e80ccd96

16

dist/client-actions.js

@@ -95,3 +95,3 @@ "use strict";

var CLIENT_PLAY_CREATURE = exports.CLIENT_PLAY_CREATURE = "CLIENT_PLAY_CREATURE";
var clientPlayCreature = exports.clientPlayCreature = function clientPlayCreature(card) {
var clientPlayCreature = exports.clientPlayCreature = function clientPlayCreature(boxId) {
return function () {

@@ -105,8 +105,8 @@ var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(dispatch, getState) {

state = getState();
unitId = (0, _util.traverseSecret)(card, state.secret);
unit = getState().game.units[unitId];
unitId = _util.Box.traverse(boxId, state.game.boxes, state.client.keys);
unit = state.game.units[unitId];
_context.next = 5;
return dispatch({
type: CLIENT_PLAY_CREATURE,
card: card,
boxId: boxId,
unit: unit

@@ -159,8 +159,4 @@ });

return function (dispatch, getState) {
var _getState$client = getState().client,
playingCard = _getState$client.playingCard,
targets = _getState$client.targets;
var privateKey = getState().secret[playingCard.id].private;
dispatch((0, _game.playCreature)({ id: playingCard.id, privateKey: privateKey, targets: targets }));
var boxId = getState().client.playingBoxId;
dispatch((0, _game.playCard)({ boxId: boxId }));
};

@@ -167,0 +163,0 @@ };

@@ -6,3 +6,3 @@ "use strict";

});
exports.clientPoll = exports.clientLoadState = exports.CLIENT_LOAD_STATE = exports.clientGetGameHash = undefined;
exports.clientPoll = exports.clientLoadState = exports.CLIENT_LOAD_STATE_DONE = exports.CLIENT_LOAD_STATE_START = exports.clientGetGameHash = undefined;

@@ -31,3 +31,7 @@ var _regenerator = require("babel-runtime/regenerator");

var CLIENT_LOAD_STATE = exports.CLIENT_LOAD_STATE = "CLIENT_LOAD_STATE";
/**
* Load the state of a game by replaying all the actions
*/
var CLIENT_LOAD_STATE_START = exports.CLIENT_LOAD_STATE_START = "CLIENT_LOAD_STATE_START";
var CLIENT_LOAD_STATE_DONE = exports.CLIENT_LOAD_STATE_DONE = "CLIENT_LOAD_STATE_DONE";
var clientLoadState = exports.clientLoadState = function clientLoadState(gameId) {

@@ -38,3 +42,3 @@ return function () {

var res, err, gameState;
var res, err, startState, hash, headRes, actionRes, action;
return _regenerator2.default.wrap(function _callee$(_context) {

@@ -69,10 +73,60 @@ while (1) {

case 11:
gameState = _context.sent;
dispatch((_dispatch = {
type: CLIENT_LOAD_STATE,
gameState: gameState
startState = _context.sent;
_context.next = 14;
return dispatch((_dispatch = {
type: CLIENT_LOAD_STATE_START,
gameState: startState
}, _defineProperty(_dispatch, _cardcore.REMOTE_ACTION, true), _defineProperty(_dispatch, "next", gameId + ".sha256"), _dispatch));
case 13:
case 14:
if (!true) {
_context.next = 33;
break;
}
_context.next = 17;
return dispatch(clientGetGameHash());
case 17:
hash = _context.sent;
_context.next = 20;
return fetch("/" + hash + "/next", {
method: "HEAD"
});
case 20:
headRes = _context.sent;
if (!(headRes.status !== 204)) {
_context.next = 23;
break;
}
return _context.abrupt("break", 33);
case 23:
_context.next = 25;
return fetch("/" + hash + "/next");
case 25:
actionRes = _context.sent;
_context.next = 28;
return actionRes.json();
case 28:
action = _context.sent;
_context.next = 31;
return dispatch(Object.assign({}, action, _defineProperty({}, _cardcore.REMOTE_ACTION, true)));
case 31:
_context.next = 14;
break;
case 33:
_context.next = 35;
return dispatch({
type: "CLIENT_LOAD_STATE_DONE"
});
case 35:
case "end":

@@ -111,2 +165,10 @@ return _context.stop();

case 2:
if (!getState().client.loadingState) {
_context3.next = 4;
break;
}
return _context3.abrupt("return");
case 4:
handle = void 0;

@@ -184,3 +246,3 @@ backoffIdx = 0;

case 8:
case 10:
case "end":

@@ -187,0 +249,0 @@ return _context3.stop();

@@ -25,7 +25,8 @@ "use strict";

desyncStates: {},
playingCard: null,
playingBoxId: null,
targetQueue: [],
targets: [],
keys: {},
started: false
started: false,
loadingState: true
};

@@ -51,3 +52,3 @@

}),
playingCard: action.card
playingBoxId: action.boxId
});

@@ -61,3 +62,3 @@ }

availableTargets: null,
playingCard: null
playingBoxId: null
});

@@ -85,2 +86,14 @@ }

if (action.type === clientActions.CLIENT_LOAD_STATE_START) {
return Object.assign({}, state, {
loadingState: true
});
}
if (action.type === clientActions.CLIENT_LOAD_STATE_DONE || action.type === actions.CREATE_GAME) {
return Object.assign({}, state, {
loadingState: false
});
}
if (action.type === actions.PLAY_CREATURE) {

@@ -87,0 +100,0 @@ return Object.assign({}, state, {

{
"name": "@cardcore/client",
"version": "0.0.1-e610b5ce",
"version": "0.0.1-e80ccd96",
"description": "streamcards client",

@@ -16,3 +16,3 @@ "main": "dist/index.js",

},
"gitHead": "e610b5ce494b91bf26736417e3c8ba011f27ae84"
"gitHead": "e80ccd9627337c33e9f62eed0f17f765917c1713"
}

@@ -1,3 +0,3 @@

import { playCreature } from "@cardcore/game";
import { traverseSecret, target as targetHelper } from "@cardcore/util";
import { playCard } from "@cardcore/game";
import { Box, target as targetHelper } from "@cardcore/util";
import ssbKeys from "@streamplace/ssb-keys";

@@ -60,9 +60,9 @@

export const CLIENT_PLAY_CREATURE = "CLIENT_PLAY_CREATURE";
export const clientPlayCreature = card => async (dispatch, getState) => {
export const clientPlayCreature = boxId => async (dispatch, getState) => {
const state = getState();
const unitId = traverseSecret(card, state.secret);
const unit = getState().game.units[unitId];
const unitId = Box.traverse(boxId, state.game.boxes, state.client.keys);
const unit = state.game.units[unitId];
await dispatch({
type: CLIENT_PLAY_CREATURE,
card,
boxId,
unit

@@ -79,5 +79,4 @@ });

export const clientPlayCreatureDone = () => (dispatch, getState) => {
const { playingCard, targets } = getState().client;
const privateKey = getState().secret[playingCard.id].private;
dispatch(playCreature({ id: playingCard.id, privateKey, targets }));
const boxId = getState().client.playingBoxId;
dispatch(playCard({ boxId }));
};

@@ -84,0 +83,0 @@

@@ -10,3 +10,7 @@ import { hashState } from "@cardcore/util";

export const CLIENT_LOAD_STATE = "CLIENT_LOAD_STATE";
/**
* Load the state of a game by replaying all the actions
*/
export const CLIENT_LOAD_STATE_START = "CLIENT_LOAD_STATE_START";
export const CLIENT_LOAD_STATE_DONE = "CLIENT_LOAD_STATE_DONE";
export const clientLoadState = gameId => async (dispatch, getState) => {

@@ -19,9 +23,24 @@ const res = await fetch(`/${gameId}.sha256`);

}
const gameState = await res.json();
dispatch({
type: CLIENT_LOAD_STATE,
gameState,
const startState = await res.json();
await dispatch({
type: CLIENT_LOAD_STATE_START,
gameState: startState,
[REMOTE_ACTION]: true,
next: `${gameId}.sha256`
});
while (true) {
const hash = await dispatch(clientGetGameHash());
const headRes = await fetch(`/${hash}/next`, {
method: "HEAD"
});
if (headRes.status !== 204) {
break;
}
const actionRes = await fetch(`/${hash}/next`);
const action = await actionRes.json();
await dispatch({ ...action, [REMOTE_ACTION]: true });
}
await dispatch({
type: "CLIENT_LOAD_STATE_DONE"
});
};

@@ -37,2 +56,5 @@

}
if (getState().client.loadingState) {
return;
}
let handle;

@@ -39,0 +61,0 @@ let backoffIdx = 0;

@@ -7,7 +7,8 @@ import * as actions from "@cardcore/game";

desyncStates: {},
playingCard: null,
playingBoxId: null,
targetQueue: [],
targets: [],
keys: {},
started: false
started: false,
loadingState: true
};

@@ -30,3 +31,3 @@

targetQueue: action.unit.onSummon.map(onSummon => onSummon.target),
playingCard: action.card
playingBoxId: action.boxId
};

@@ -41,3 +42,3 @@ }

availableTargets: null,
playingCard: null
playingBoxId: null
};

@@ -71,2 +72,19 @@ }

if (action.type === clientActions.CLIENT_LOAD_STATE_START) {
return {
...state,
loadingState: true
};
}
if (
action.type === clientActions.CLIENT_LOAD_STATE_DONE ||
action.type === actions.CREATE_GAME
) {
return {
...state,
loadingState: false
};
}
if (action.type === actions.PLAY_CREATURE) {

@@ -73,0 +91,0 @@ return {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc