Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import com.gamejolt.API;
- /**
- * ...
- * @author Faisal
- */
- public class GameJoltConnect
- {
- private static var g_instance:GameJoltConnect;
- public var gameJoltApi:API;
- private var userVerified:Boolean = false;
- private var _gameId:int = 22261;
- private var _privateKey:String = "1343248e9b2ca81c51d6a45574cc5f04";
- public var userName:String = "Guest";
- public var userToken:String = "000000";
- private var firstTrophyId:int = 6100;
- private var secondTrophyId:int = 6101;
- private var thirdTrophyId:int = 6102;
- public function GameJoltConnect()
- {
- trace("Gamejolt API initialized");
- gameJoltApi = new API();
- }
- public static function get instance():GameJoltConnect
- {
- if (g_instance == null)
- {
- g_instance = new GameJoltConnect();
- }
- return g_instance;
- }
- public function authUser(_uName:String, _uToken:String):void
- {
- Main.printLog("authenticating user...");
- trace("authenticating user...");
- userName = _uName;
- userToken = _uToken;
- gameJoltApi.authUser(_gameId, _privateKey, _uName, _uToken, onUserAuthCallback);
- }
- private function onUserAuthCallback(success:Boolean):void
- {
- if (success)
- {
- Main.printLog("user verified Success");
- trace("user verified Success");
- userVerified = true;
- Main.userNameLabel.text = "Username:"+userName;
- Main.tokenLabel.text = "Token:"+userToken;
- //gameJoltApi.getKeyData(_gameId, _privateKey, "BRONZE", onBronzeDataCallback, userName, userToken);
- //gameJoltApi.getKeyData(_gameId, _privateKey, "SILVER", onSilverDataCallback, userName, userToken);
- }
- else
- {
- Main.printLog("user verified Failed. Guest Login");
- //trace("user authentication Failed");
- userName = "Guest";
- Main.userNameLabel.text = "Username:"+userName;
- Main.tokenLabel.text = "Token:NA";
- userVerified = false;
- }
- }
- //private function onSilverDataCallback(data:String):void
- //{
- //trace("Checking Silver Status");
- //if (data != null)
- //{
- //trace("Silver Data:" + data);
- //isSilverAchieved = data;
- //}
- //}
- //
- //private function onBronzeDataCallback(data:String):void
- //{
- //trace("Checking Bronze Status");
- //if (data != null)
- //{
- //trace("Bronze Data:" + data);
- //isBronzeAchieved = data;
- //}
- //}
- public function setKeyData(key:String, data:String):void
- {
- if (userVerified)
- {
- Main.printLog("SetData "+data+" with Key: "+key);
- gameJoltApi.setKeyData(_gameId, _privateKey, key, data, userName, userToken);
- }
- else
- Main.printLog("Not GameJolt User");
- }
- public function getKeyData(key:String):void
- {
- if (userVerified)
- {
- Main.printLog("getData with Key: "+key);
- gameJoltApi.getKeyData(_gameId, _privateKey, key, onGetDataCallback, userName, userToken);
- }
- else
- Main.printLog("Not GameJolt User");
- }
- private function onGetDataCallback(data:String):void
- {
- //trace("Checking Silver Status");
- Main.printLog("GetData Callback recieved");
- if (data != null)
- {
- Main.printLog("Recieved Data:"+data);
- }
- }
- public function addHighScore(score:int = 0):void
- {
- if (userVerified)
- {
- trace("HighScore Send");
- Main.printLog("HighScore Send");
- gameJoltApi.setHighscore(_gameId, _privateKey, String(score), Number(score), userName, userToken);
- }
- else
- {
- trace("HS Set Guest");
- Main.printLog("HighScore Send - Guest");
- gameJoltApi.setHighscore(_gameId, _privateKey, String(score), Number(score), userName, userToken, userName);
- }
- }
- public function addTrophy(id:int = 0):void
- {
- if (!userVerified)
- {
- trace("Trophy adding failed. invalid user data");
- Main.printLog("Trophy adding failed. invalid user data");
- return;
- }
- if (id == 0)
- {
- Main.printLog("Trophy added. 20 Clicks.");
- gameJoltApi.addTrophyAchieved(_gameId, _privateKey, userName, userToken, firstTrophyId);
- //if (isBronzeAchieved != "Y")
- //{
- //trace("Got Bronze Trophy");
- //isBronzeAchieved = "Y";
- //gameJoltApi.setKeyData(_gameId, _privateKey, "BRONZE", "Y", userName, userToken);
- //gameJoltApi.addTrophyAchieved(_gameId, _privateKey, userName, userToken, bronzeTrophyId);
- //}
- //else
- //{
- //trace("Bronze Trophy achieved already");
- //}
- }
- else if (id == 1)
- {
- Main.printLog("Trophy added. 40 Clicks.");
- gameJoltApi.addTrophyAchieved(_gameId, _privateKey, userName, userToken, secondTrophyId);
- //if (isSilverAchieved != "Y")
- //{
- //trace("Got Silver Trophy too.Cool");
- //isSilverAchieved = "Y";
- //gameJoltApi.setKeyData(_gameId, _privateKey, "SILVER", "Y", userName, userToken);
- //gameJoltApi.addTrophyAchieved(_gameId, _privateKey, userName, userToken, silverTrophyId);
- //}
- //else
- //{
- //trace("Silver Trophy achieved already");
- //}
- }
- else if (id == 2)
- {
- Main.printLog("Trophy added. 5 Breakout Points.");
- gameJoltApi.addTrophyAchieved(_gameId, _privateKey, userName, userToken, thirdTrophyId);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement