Created
January 13, 2009 09:21
-
-
Save neuecc/46381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() | |
{ | |
// GWRE2のモード対応表 | |
var Modes = | |
{ | |
"Deadline": "0", | |
"King": "5", | |
"Evolved": "1", | |
"Pacifism": "4", | |
"Wave": "3", | |
"Sequence": "2", | |
"All": "" | |
}; | |
// モードのnoun_type | |
var noun_type_gwre2 = { | |
_name: "Mode", | |
suggest: function(text) | |
{ | |
var suggestions = []; | |
for (var modeName in Modes) | |
{ | |
if (modeName.match("^" + text, "i")) | |
{ | |
suggestions.unshift(CmdUtils.makeSugg(modeName)); | |
} | |
else if (!modeName.match("All")) | |
{ | |
suggestions.push(CmdUtils.makeSugg(modeName)); | |
} | |
} | |
return suggestions; | |
} | |
}; | |
// データ保持クラス | |
function Score(mode, tag, rank, score) | |
{ | |
this.mode = mode; | |
this.tag = tag; | |
this.rank = rank; | |
this.score = score; | |
} | |
Score.prototype = | |
{ | |
// 単品取得 | |
GetFromLeaderboard: function() | |
{ | |
var array = Score.Query(this.mode, this.tag, 1); | |
this.rank = array.eq(1).text(); | |
this.tag = array.eq(2).text(); | |
this.score = array.eq(3).text(); | |
}, | |
// プレビュー用表記 | |
toString: function() | |
{ | |
return "<p>" + this.tag + ":" + this.mode + "<br />" | |
+ "Rank:" + this.rank + " | Score:" + this.score + "</p>"; | |
} | |
} | |
// ネットワーク問い合わせ | |
Score.Query = function(mode, tag, num) | |
{ | |
var req = jQuery.ajax({ | |
method: "GET", | |
url: "http://www.bizarrecreations.com/XBLLeaderboardSvc/Service.asmx/getLeaderboardNearGamertag", | |
data: { | |
gameId: 2, | |
leaderboardid: Modes[mode], | |
gamerTag: tag, | |
numToShow: num | |
}, | |
async: false | |
}); | |
return jQuery(req.responseXML).find("string"); | |
} | |
// モード固定で周囲のスコア取得 | |
Score.GetNearGamerTag = function(mode, tag) | |
{ | |
var scoreList = []; | |
var array = Score.Query(mode, tag, 7); | |
var score = new Score(mode, tag); | |
array.each(function(index) | |
{ | |
if (index == 0) return; // 先頭は除外 | |
switch (index % 3) | |
{ | |
case 0: | |
score.score = jQuery(this).text(); | |
scoreList.push(score); | |
score = new Score(mode); | |
break; | |
case 1: | |
score.rank = jQuery(this).text(); | |
break; | |
case 2: | |
score.tag = jQuery(this).text(); | |
break; | |
} | |
}); | |
return scoreList; | |
} | |
var result = ""; // 実行時張りつけ用保存変数 | |
// ここからコマンド本体 | |
CmdUtils.CreateCommand({ | |
name: "gwre2", | |
icon: "http://www.bizarrecreations.com/favicon.ico", | |
homepage: "http://neue.cc/", | |
author: { name: "neuecc", email: "[email protected]" }, | |
description: "GWRE2のランキングを取得する", | |
takes: { "GamerTag": noun_arb_text }, | |
modifiers: { "mode": noun_type_gwre2 }, | |
preview: function(view, tag, mods) | |
{ | |
result = ""; | |
var scoreList = []; | |
var tag = tag.text; | |
var mode = mods["mode"].text; | |
// modeが空の場合はプレビューにヘルプを置いてリターン | |
if (mode == "") | |
{ | |
view.innerHTML = "please input \"GamerTag\" mode \"Mode\"<br /><br />" + | |
"ModeList:<br />" + | |
"All<br />" + | |
"Deadline<br />" + | |
"King<br />" + | |
"Evolved<br />" + | |
"Pacifism<br />" + | |
"Wave<br />" + | |
"Sequence<br />"; | |
return; | |
} | |
// データ読み込み | |
view.innerHTML = "loading..."; | |
if (mode == "All") // modeがAll時 | |
{ | |
for (var mode in Modes) | |
{ | |
var score = new Score(mode, tag); | |
score.GetFromLeaderboard(); | |
if (score.tag == "") break; // 読みこみに失敗した時はループを抜ける | |
scoreList.push(score); | |
// プレビュー用処理・実行時用テキスト保存 | |
view.innerHTML = "Now Loading...<br />" + score; | |
result += score.mode + "[Rank:" + score.rank + | |
"|Score:" + score.score + "]"; | |
} | |
} | |
else // modeが各モード時 | |
{ | |
scoreList = Score.GetNearGamerTag(mode, tag); | |
} | |
// プレビュー領域に書き出し | |
if (scoreList.length > 0) | |
{ | |
var preview = ""; | |
for (var key in scoreList) | |
{ | |
preview += scoreList[key]; | |
} | |
view.innerHTML = preview; | |
} | |
else | |
{ | |
view.innerHTML = "Not Found."; | |
} | |
}, | |
execute: function(tag, mods) | |
{ | |
var tag = tag.text; | |
var mode = mods["mode"].text; | |
// modeが個別選択されている時はスコア取得 | |
if (mode != "" && mode != "All") | |
{ | |
var score = new Score(mode, tag); | |
score.GetFromLeaderboard(); | |
result = score.score; | |
}; | |
CmdUtils.setSelection(result); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment