@cardcore/client
Advanced tools
Comparing version 0.0.1-1f746c46 to 0.0.1-2bfe84b6
@@ -12,2 +12,16 @@ "use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _clientPoll = require("./client-poll"); | ||
Object.keys(_clientPoll).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _clientPoll[key]; | ||
} | ||
}); | ||
}); | ||
var _game = require("@cardcore/game"); | ||
@@ -17,3 +31,3 @@ | ||
var _ssbKeys = require("ssb-keys"); | ||
var _ssbKeys = require("@streamplace/ssb-keys"); | ||
@@ -83,3 +97,3 @@ var _ssbKeys2 = _interopRequireDefault(_ssbKeys); | ||
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 () { | ||
@@ -93,8 +107,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 | ||
@@ -147,8 +161,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 })); | ||
}; | ||
@@ -211,6 +221,37 @@ }; | ||
var CLIENT_GENERATE_IDENTITY = exports.CLIENT_GENERATE_IDENTITY = "CLIENT_GENERATE_IDENTITY"; | ||
var CARDCORE_IDENTITY = "CARDCORE_IDENTITY"; | ||
var clientGenerateIdentity = exports.clientGenerateIdentity = function clientGenerateIdentity() { | ||
var storage = void 0; | ||
if ((typeof localStorage === "undefined" ? "undefined" : _typeof(localStorage)) === "object") { | ||
storage = localStorage; | ||
} else { | ||
// noop i guess? idk this only happens in jsdom? | ||
storage = { | ||
getItem: function getItem() { | ||
return null; | ||
}, | ||
setItem: function setItem() { | ||
return null; | ||
}, | ||
removeItem: function removeItem() { | ||
return null; | ||
} | ||
}; | ||
} | ||
var keys = void 0; | ||
if (storage.getItem(CARDCORE_IDENTITY)) { | ||
try { | ||
keys = JSON.parse(storage.getItem(CARDCORE_IDENTITY)); | ||
} catch (e) { | ||
console.error("error parsing cardcore identity, clearing", e); | ||
storage.removeItem(CARDCORE_IDENTITY); | ||
} | ||
} | ||
if (!keys) { | ||
keys = _ssbKeys2.default.generate(); | ||
storage.setItem(CARDCORE_IDENTITY, JSON.stringify(keys)); | ||
} | ||
return { | ||
type: CLIENT_GENERATE_IDENTITY, | ||
keys: _ssbKeys2.default.generate() | ||
keys: keys | ||
}; | ||
@@ -217,0 +258,0 @@ }; |
@@ -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-1f746c46", | ||
"version": "0.0.1-2bfe84b6", | ||
"description": "streamcards client", | ||
@@ -13,3 +13,10 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "1f746c46c9911e36a1e9be89edf6da902e8ff20f" | ||
"dependencies": { | ||
"@cardcore/game": "0.0.1-2bfe84b6", | ||
"@cardcore/util": "0.0.1-2bfe84b6", | ||
"@streamplace/ssb-keys": "7.0.18", | ||
"babel-runtime": "^6.26.0", | ||
"cardcore": "0.0.1-2bfe84b6" | ||
}, | ||
"gitHead": "2bfe84b63d6352d5a91c2ba8a0e0afc41e6798e5" | ||
} |
@@ -1,4 +0,7 @@ | ||
import { playCreature } from "@cardcore/game"; | ||
import { traverseSecret, target as targetHelper } from "@cardcore/util"; | ||
import ssbKeys from "ssb-keys"; | ||
import { playCard } from "@cardcore/game"; | ||
import { Box, target as targetHelper } from "@cardcore/util"; | ||
import ssbKeys from "@streamplace/ssb-keys"; | ||
export * from "./client-poll"; | ||
/** | ||
@@ -57,9 +60,9 @@ * This file should contain web-specific actions extranious to the game state | ||
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 | ||
@@ -76,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 })); | ||
}; | ||
@@ -111,6 +113,31 @@ | ||
export const CLIENT_GENERATE_IDENTITY = "CLIENT_GENERATE_IDENTITY"; | ||
const CARDCORE_IDENTITY = "CARDCORE_IDENTITY"; | ||
export const clientGenerateIdentity = () => { | ||
let storage; | ||
if (typeof localStorage === "object") { | ||
storage = localStorage; | ||
} else { | ||
// noop i guess? idk this only happens in jsdom? | ||
storage = { | ||
getItem: () => null, | ||
setItem: () => null, | ||
removeItem: () => null | ||
}; | ||
} | ||
let keys; | ||
if (storage.getItem(CARDCORE_IDENTITY)) { | ||
try { | ||
keys = JSON.parse(storage.getItem(CARDCORE_IDENTITY)); | ||
} catch (e) { | ||
console.error("error parsing cardcore identity, clearing", e); | ||
storage.removeItem(CARDCORE_IDENTITY); | ||
} | ||
} | ||
if (!keys) { | ||
keys = ssbKeys.generate(); | ||
storage.setItem(CARDCORE_IDENTITY, JSON.stringify(keys)); | ||
} | ||
return { | ||
type: CLIENT_GENERATE_IDENTITY, | ||
keys: ssbKeys.generate() | ||
keys | ||
}; | ||
@@ -117,0 +144,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51785
13
860
5
8
+ Added@streamplace/ssb-keys@7.0.18
+ Addedbabel-runtime@^6.26.0
+ Addedcardcore@0.0.1-2bfe84b6
+ Added@babel/runtime@7.26.0(transitive)
+ Added@cardcore/game@0.0.1-2bfe84b6(transitive)
+ Added@cardcore/util@0.0.1-2bfe84b6(transitive)
+ Added@streamplace/chloride@2.2.11(transitive)
+ Added@streamplace/ssb-keys@7.0.18(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcardcore@0.0.1-2bfe84b6(transitive)
+ Addedchloride@2.4.1(transitive)
+ Addedchloride-test@1.2.4(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.0(transitive)
+ Addeded2curve@0.1.4(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedis-electron@2.2.2(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-buffer@2.0.11(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify@1.1.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedlibsodium@0.7.15(transitive)
+ Addedlibsodium-wrappers@0.7.15(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedmath-intrinsics@1.0.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednan@2.22.0(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addednode-gyp-build@4.8.4(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedprivate-box@0.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedredux@4.2.1(transitive)
+ Addedredux-immutable-state-invariant@2.1.0(transitive)
+ Addedredux-thunk@2.4.2(transitive)
+ Addedregenerator-runtime@0.11.10.14.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsha.js@2.4.112.4.5(transitive)
+ Addedsodium-browserify@1.3.0(transitive)
+ Addedsodium-browserify-tweetnacl@0.2.6(transitive)
+ Addedsodium-chloride@1.1.2(transitive)
+ Addedsodium-native@2.4.93.4.1(transitive)
+ Addedtweetnacl@0.14.51.0.3(transitive)
+ Addedtweetnacl-auth@0.3.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)