Skip to content
Permalink
Browse files

changes for gameeJS 2.1.0

  • Loading branch information...
MartinPlascencia committed Sep 5, 2018
1 parent 57943c3 commit a802e992eb0ed21cdc8267352a975bb88be5793a
Showing with 1,269 additions and 723 deletions.
  1. +2 −2 gamee/dist/gamee-js.min.js
  2. +1 −1 gamee/dist/gamee-js.min.js.map
  3. +96 −7 gamee/src/core.js
  4. +109 −5 gamee/src/gameeAPI.js
  5. +2 −8 gamee/src/index.js
  6. +8 −77 gamee/src/platform_bridge.js
  7. +1,044 −616 package-lock.json
  8. +7 −7 package.json

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -107,8 +107,8 @@ export var core = (function () {

/** internal variables/constants (uppercase) coupled inside separate object for potential easy referencing */
var internals = {
VERSION: "2.0", // version of the gamee library
CAPABILITIES: ["ghostMode", "saveState", "replay", "socialData"], // supported capabilities
VERSION: "2.1.0", // version of the gamee library
CAPABILITIES: ["ghostMode", "saveState", "replay", "socialData","rewardedAds","coins","logEvents","playerData"], // supported capabilities
variant: 0, // for automating communication with server
soundUnlocked: false,
onReady: noop, // for intercepting real onReady because of behind the scenes variant handling
@@ -168,7 +168,7 @@ export var core = (function () {
// might fail if controller of this type doesnt exist
var error = null;
try {
if (this.native.platform === "web" || this.native.platform === "fb") {
if (this.native.platform === "web") {
responseData.controller = core.controller.requestController(ctrlType, { enableKeyboard: true });
this._bindKeyboardTriggers(responseData.controller);
} else {
@@ -305,7 +305,7 @@ export var core = (function () {
* Data has the same format as data received in onReady callback.
* Data must be string = responsibility for turning data structure into string is left to the game!
*/
core.gameOver = function (opt_replayData) {
core.gameOver = function (opt_replayData,opt_saveState) {
// var allOk = ((data !== undefined) && (typeof data === "string")) || (data === undefined);
// if (!allOk) console.error("Data provided to gameOver function must be string.");
// gameeNative.gameOver(gamee, internals.variant, allOk ? data : "");
@@ -318,6 +318,7 @@ export var core = (function () {
throw "Replay data must have `data` property";
}
requestData.replayData = opt_replayData;
requestData.state = opt_saveState;
}
core.native.createRequest("gameOver", requestData);
};
@@ -329,16 +330,104 @@ export var core = (function () {
* share must be expression evaluating to either true or false; it indicates, whether the game progress should be shared on feed
*/
core.gameSave = function (data, share) {

if(!cache.capabilities.saveState)
throw "Save State not supported, you must add the capability on gamee.Init"

core.native.createRequest("saveState", { state: data, share: share });
};

core.requestSocial = function (cb) {
this.native.createRequest("requestSocial", function (responseData) {
core.requestSocial = function (cb,numberOfPlayers) {

if(!cache.capabilities.socialData)
throw "Social Data not supported, you must add the capability on gamee.Init"

this.native.createRequest("requestSocial", numberOfPlayers,function (responseData) {
cb(null, responseData);
});
};


core.logEvent = function (eventName,eventValue) {

if(!cache.capabilities.logEvents)
throw "Log Events not supported, you must add the capability on gamee.Init"

//var valuesToLogString = JSON.stringify(eventValue)

this.native.createRequest("logEvent", {eventName,eventValue},function(error){
if(error){
throw error
}
});

};

core.requestPlayerReplay = function (userID,cb) {

if(!cache.capabilities.replay)
throw "Replays not supported, you must add the capability on gamee.Init"

this.native.createRequest("requestPlayerReplay", {userID}, function (responseData) {
cb(null, responseData);
});
};

core.requestPlayerSaveState = function (userID,cb) {
this.native.createRequest("requestPlayerSaveState", {userID}, function (responseData) {
cb(null, responseData);
});
};

core.purchaseItem = function (options,cb) {

if(!cache.capabilities.coins)
throw "Purchases not supported, you must add the capability on gamee.Init"

if (options) {
var propertiesList = ["coinsCost","itemName"]
propertiesList.forEach(function(property){
if(!options.hasOwnProperty(property))
throw "Purchase Options must have `"+property+"` property"
})
}

console.log(options)

this.native.createRequest("purchaseItem",options, function (responseData) {
cb(null, responseData);
});
};

core.loadRewardedVideo = function (cb) {

if(!cache.capabilities.rewardedAds)
throw "Rewarded Ads not supported, you must add the capability on gamee.Init"

this.native.createRequest("loadRewardedVideo", function (responseData) {
cb(null, responseData);
});
};

core.showRewardedVideo = function (cb) {

if(!cache.capabilities.rewardedAds)
throw "Rewarded Ads not supported, you must add the capability on gamee.Init"

this.native.createRequest("showRewardedVideo", function (responseData) {
cb(null, responseData);
});
};

core.requestPlayerData = function (cb) {

if(!cache.capabilities.playerData)
throw "Player Data not supported, you must add the capability on gamee.Init"

this.native.createRequest("requestPlayerData",function (responseData) {
cb(null, responseData);
});
};

core.startSignal = function (data) {
var error;

@@ -162,15 +162,15 @@ Gamee.prototype = (function () {
* @param {Gamee~ReplayData} [opt_replayData]
* @param {Gamee~voidCallback} [opt_cb]
*/
gameOver: function (opt_replayData, opt_cb) {
gameOver: function (opt_replayData, opt_cb, opt_saveState) {
if (typeof opt_replayData === "function")
opt_cb = opt_replayData;
else if (typeof opt_replayData !== "undefined")
validateDataType(opt_replayData, "object", "opt_replayData", "gamee.gameOver");

opt_cb = opt_cb || cbError;
validateDataType(opt_cb, "function", "opt_cb", "gamee.gameOver");
core.gameOver(opt_replayData);
core.gameOver(opt_replayData,opt_saveState);
opt_cb(null);
},

@@ -180,18 +180,122 @@ Gamee.prototype = (function () {
* @memberof Gamee
* @param {Gamee~requestSocialDataCallback} cb
*/
requestSocial: function (cb) {
requestSocial: function (cb,numberOfPlayers) {
validateDataType(cb, "function", "cb", "gamee.requestSocial");

// functionality supposed to be removed once we do update for iOS
var data = core.requestSocial(function (error, responseData) {
var modifiedResponse = !responseData.hasOwnProperty("socialData") ? { socialData: responseData } : responseData
cb(null, modifiedResponse);
});
},numberOfPlayers);

// var data = core.requestSocial(cb);
//cb(null, data);
}
},

/**
* logEvent
*
* @memberof Gamee
* @param {string} eventName
* @param {number} valueToSum
* @param {string} parameters
*/
logEvent: function (eventName,eventValue) {

validateDataType(eventName,"string","eventName","gamee.logEvent")

if(!eventName || eventName.length > 24){
console.error("eventName parameter cant be null and can only contain up to 24 characters");
return
}

validateDataType(eventValue,"string","eventValue","gamee.logEvent")

if(!eventValue || eventValue.length > 24){
console.error("eventValue parameter cant be null and can only contain up to 24 characters");
return
}

core.logEvent(eventName,eventValue)
},

/**
* requestPlayerReplay
*
* @memberof Gamee
* @param {number} userID
* @param {Gamee~requestPlayerReplayDataCallback} cb
*/
requestPlayerReplay: function (userID, cb) {

validateDataType(userID, "number", "userID", "gamee.requestPlayerReplay");
validateDataType(cb, "function", "cb", "gamee.requestPlayerReplay");

core.requestPlayerReplay(userID, cb);
},

/**
* requestPlayerSaveState
*
* @memberof Gamee
* @param {number} userID
* @param {Gamee~requestPlayerSaveStateDataCallback} cb
*/
requestPlayerSaveState: function (userID, cb) {

validateDataType(userID, "number", "userID", "gamee.requestPlayerSaveState");
validateDataType(cb, "function", "cb", "gamee.requestPlayerSaveState");

core.requestPlayerSaveState(userID, cb);
},

/*
*puchaseitem
*@member of Gamee
*@param {object} purchaseDetails
*@param {Gamee~purchaseItemDataCallback} cb
*/
purchaseItem: function(purchaseDetails,cb){

validateDataType(purchaseDetails,"object","purchaseDetails","gamee.purchaseItem");
validateDataType(cb,"function","cb","gamee.purchaseItem")

core.purchaseItem(purchaseDetails,cb)
},

/*
*loadRewardedVideo
*@member of Gamee
*@param {Gamee~loadRewardedVideo} cb
*/
loadRewardedVideo: function(cb){

validateDataType(cb,"function","cb","gamee.loadRewardedVideo")
core.loadRewardedVideo(cb)
},

/*
*showRewardedVideo
*@member of Gamee
*@param{Gamee~showRewardedVideo} cb
*/
showRewardedVideo: function(cb){

validateDataType(cb,"function","cb","gamee.showRewardedVideo")
core.showRewardedVideo(cb)
},

/*
*requestPlayerData
*@member of Gamee
*@param{Gamee~requestPlayerData} cb
*/
requestPlayerData: function(cb){

validateDataType(cb,"function","cb","gamee.requestPlayerData")
core.requestPlayerData(cb)
},
};

/**
@@ -1,7 +1,7 @@
import { } from "../libs/shims.js"
import { Gamee } from "./gameeAPI.js"
import { core } from "./core.js"
import { PlatformAPI, PlatformBridge, PostMessageBridge, MobileBridge, FacebookBridge } from "./platform_bridge.js"
import { PlatformAPI, PlatformBridge, PostMessageBridge, MobileBridge } from "./platform_bridge.js"


/**
@@ -25,10 +25,7 @@ var platformBridge = (function () {
/* current user agent */
var userAgent = navigator.userAgent.toLowerCase();

if ((window.parent !== window) && (/facebook\./.test(document.referrer) || /messenger\.com/.test(document.referrer))) { // FB
// TODO fb platform
platformType = "fb";
} else if (/iphone|ipod|ipad/.test(userAgent)) { // test ios device
if (/iphone|ipod|ipad/.test(userAgent)) { // test ios device
// user agent is use to determine current enviroment

// Test if window with game have a parent (loading in iframe)
@@ -63,9 +60,6 @@ var platformBridge = (function () {
case "android":
platformBridge = new MobileBridge("android");
break;
case "fb":
platformBridge = new FacebookBridge("fb");
break;
default:
throw "Can't identify the platform";
}
Oops, something went wrong.

0 comments on commit a802e99

Please sign in to comment.
You can’t perform that action at this time.