Skip to content

Add automatic rank update. #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/GlobalVariables.as
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ package
public var songStartHash:String = "0";
public var songCache:Array = [];
public var songHighscores:Object = {};
public var shouldUpdateRank:Boolean = false;

///- User Vars
public var userSession:String = "0";
Expand Down
2 changes: 2 additions & 0 deletions src/com/flashfla/net/WebRequest.as
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ package com.flashfla.net
active = true;
loaded = false;
_loader.addEventListener(Event.COMPLETE, e_loadComplete);
_loader.addEventListener(IOErrorEvent.NETWORK_ERROR, e_loadError)
_loader.addEventListener(IOErrorEvent.IO_ERROR, e_loadError);
_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, e_loadError);
}
Expand All @@ -88,6 +89,7 @@ package com.flashfla.net
active = false;
loaded = true;
_loader.removeEventListener(Event.COMPLETE, e_loadComplete);
_loader.removeEventListener(IOErrorEvent.NETWORK_ERROR, e_loadError)
_loader.removeEventListener(IOErrorEvent.IO_ERROR, e_loadError);
_loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, e_loadError);
}
Expand Down
2 changes: 2 additions & 0 deletions src/game/GameResults.as
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ package game
240,
Alert.DARK_GREEN
);

_gvars.shouldUpdateRank = true;
}

// Check raw score vs level ranks and update.
Expand Down
22 changes: 18 additions & 4 deletions src/menu/MainMenu.as
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ package menu

buildMenuItems();
SystemUtil.gc();

// Trigger the update of ranks on arrival if flag has been set.
if (_gvars.shouldUpdateRank)
{
e_statUpdaterClick(null);
}

return isFound;
}

Expand Down Expand Up @@ -465,15 +472,17 @@ package menu
rankUpdateThrobber.visible = false;
this.addChild(rankUpdateThrobber);
}

if (rankUpdateThrobber.running)
{
return;
}

var wr:WebRequest = new WebRequest(Constant.USER_RANKS_UPDATE_URL, c_rankComplete, c_rankFail);
wr.load({"session": _gvars.userSession});
_gvars.shouldUpdateRank = true; // Prevent songs from being started while this is running.
rankUpdateThrobber.visible = true;
rankUpdateThrobber.start();

function c_rankComplete(e:* = null):void
var c_rankComplete:Function = function(e:* = null):void
{
var resp:Object = JSON.parse(e.target.data);
if (_gvars.gameMain.activePanel is MainMenu)
Expand All @@ -482,17 +491,22 @@ package menu
rankUpdateThrobber.stop();
rankUpdateThrobber.visible = false;
}
_gvars.shouldUpdateRank = false;
}

function c_rankFail(e:*):void
var c_rankFail:Function = function(e:* = null):void
{
Alert.add(_lang.string("skill_rank_update_fail"), 90, Alert.RED);
if (_gvars.gameMain.activePanel is MainMenu)
{
rankUpdateThrobber.stop();
rankUpdateThrobber.visible = false;
}
_gvars.shouldUpdateRank = false;
}

var wr:WebRequest = new WebRequest(Constant.USER_RANKS_UPDATE_URL, c_rankComplete, c_rankFail);
wr.load({"session": _gvars.userSession});
}
}
}
9 changes: 9 additions & 0 deletions src/menu/MenuSongSelection.as
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,16 @@ package menu
private function playSong(level:int):void
{
if (level < 0)
{
Alert.add("Invalid Level", 120, Alert.RED);
return;
}

if (_gvars.shouldUpdateRank)
{
Alert.add("Ranks currently updating.", 120, Alert.RED);
return;
}

_gvars.songQueue = [];
var songInfo:SongInfo = _playlist.getSongInfo(level);
Expand Down