Skip to content

Instantly share code, notes, and snippets.

@sambao21
Created May 27, 2011 04:54
Show Gist options
  • Save sambao21/994664 to your computer and use it in GitHub Desktop.
Save sambao21/994664 to your computer and use it in GitHub Desktop.
angry birds, king and 5 birds
(function () {
var RealXMLHttpRequest = XMLHttpRequest;
var FakeXMLHttpRequest = function () {
this._req = new RealXMLHttpRequest();
};
FakeXMLHttpRequest.prototype = {
abort: function () {
this._req.abort.apply(this._req, arguments);
},
getAllResponseHeaders: function () {
return this._req.getAllResponseHeaders.apply(this._req, arguments);
},
open: function () {
this._url = arguments[1];
this._req.open.apply(this._req, arguments);
},
overrideMimeType: function () {
this._req.overrideMimeType.apply(this._req, arguments);
},
send: function () {
this._req.send.apply(this._req, arguments);
},
sendAsBinary: function () {
this._req.sendAsBinary.apply(this._req, arguments);
},
setRequestHeader: function () {
this._req.setRequestHeader.apply(this._req, arguments);
},
get multipart() {
return this._req.multipart;
},
set multipart(value) {
this._req.multipart = value;
},
get onreadystatechange() {
return this._req.onreadystatechange;
},
set onreadystatechange(value) {
this._req.onreadystatechange = value;
},
get readyState() {
return this._req.readyState;
},
get response() {
return this._req.response;
},
get responseText() {
return this._hookResponseText(this._req.responseText);
},
get responseXML() {
return this._req.responseXML;
},
get status() {
return this._req.status;
},
get statusText() {
return this._req.statusText;
},
get upload() {
return this._req.upload;
},
get withCredentials() {
return this._req.withCredentials;
},
_hookResponseText: function (responseText) {
try {
if (/Level[0-9]+.json$/.test(this._url)) {
var jsonData = JSON.parse(responseText);
jsonData = this._modifyAngryBirdLevel(jsonData);
responseText = JSON.stringify(jsonData);
}
} catch (ex) {
}
return responseText;
},
_modifyAngryBirdLevel: function(jsonData) {
return {
"camera": [
{
"bottom": -46.256,
"id": "Slingshot",
"left": -26.971,
"right": 39.889,
"top": -46.256,
"x": 18.709,
"y": -12.826
},
{
"bottom": -43.89,
"id": "Castle",
"left": 9.864,
"right": 72.625,
"top": -43.89,
"x": 53.495,
"y": -12.509
}
],
"counts": {
"birds": 5,
"blocks": 30
},
"id": "pack1/Level1.lua",
"scoreEagle": 37000,
"scoreGold": 52000,
"scoreSilver": 50000,
"theme": "BACKGROUND_BLUE_GRASS",
"world": {
"bird_1": {
"angle": 0,
"id": "BIRD_RED",
"x": 0,
"y": -0.974
},
"bird_2": {
"angle": 0,
"id": "BIRD_BLUE",
"x": 15.394,
"y": -1.02
},
"bird_3": {
"angle": 0,
"id": "BIRD_BLACK",
"x": 12.167,
"y": -1.019
},
"bird_4": {
"angle": 0,
"id": "BIRD_WHITE",
"x": 7.167,
"y": -1.019
},
"bird_5": {
"angle": 0,
"id": "BIRD_YELLOW",
"x": 10.167,
"y": -1.019
},
"block_1": {
"angle": 0.827,
"id": "PIG_BASIC_SMALL",
"x": 54.169,
"y": -13.88
},
"block_10": {
"angle": 90,
"id": "WOOD_BLOCK_2X1",
"x": 54.301,
"y": -23.605
},
"block_11": {
"angle": 270.084,
"id": "WOOD_BLOCK_8X1",
"x": 50.304,
"y": -6.748
},
"block_12": {
"angle": 269.86,
"id": "WOOD_BLOCK_8X1",
"x": 57.463,
"y": -6.749
},
"block_13": {
"angle": 359.986,
"id": "WOOD_BLOCK_8X1",
"x": 53.941,
"y": -11.222
},
"block_14": {
"angle": 90.018,
"id": "WOOD_BLOCK_8X1",
"x": 52.182,
"y": -15.696
},
"block_15": {
"angle": 89.994,
"id": "WOOD_BLOCK_8X1",
"x": 55.996,
"y": -15.696
},
"block_16": {
"angle": 179.983,
"id": "WOOD_BLOCK_4X1",
"x": 54.158,
"y": -20.17
},
"block_17": {
"angle": 359.747,
"id": "WOOD_BLOCK_4X1",
"x": 53.921,
"y": -3.317
},
"block_18": {
"angle": 359.812,
"id": "WOOD_BLOCK_4X1",
"x": 53.933,
"y": -8.342
},
"block_19": {
"angle": 0,
"id": "PIG_KING",
"x": 60.169,
"y": -3.88
},
"block_20": {
"angle": 0,
"id": "PIG_KING",
"x": 48.169,
"y": -3.88
},
"block_21": {
"angle": 0,
"id": "PIG_KING",
"x": 65.169,
"y": -3.88
},
"block_22": {
"angle": 0,
"id": "PIG_KING",
"x": 52.169,
"y": -3.88
},
"block_23": {
"angle": 0,
"id": "PIG_KING",
"x": 60.169,
"y": -6.88
},
"block_24": {
"angle": 0,
"id": "PIG_KING",
"x": 48.169,
"y": -6.88
},
"block_25": {
"angle": 0,
"id": "PIG_KING",
"x": 67.169,
"y": -6.88
},
"block_26": {
"angle": 0,
"id": "PIG_KING",
"x": 55.169,
"y": -6.88
},
"block_27": {
"angle": 0,
"id": "PIG_KING",
"x": 80.169,
"y": -10.88
},
"block_28": {
"angle": 0,
"id": "PIG_KING",
"x": 30.169,
"y": -10.88
},
"block_29": {
"angle": 0,
"id": "PIG_KING",
"x": 77.169,
"y": -15.88
},
"block_30": {
"angle": 0,
"id": "PIG_KING",
"x": 49.169,
"y": -15.88
},
"block_2": {
"angle": 89.561,
"id": "ICE_BLOCK_4X1",
"x": 52.58,
"y": -5.822
},
"block_3": {
"angle": 90.221,
"id": "ICE_BLOCK_4X1",
"x": 55.35,
"y": -5.83
},
"block_4": {
"angle": 0,
"id": "MISC_ESTRADE_9X3",
"x": 49.509,
"y": -1.3
},
"block_5": {
"angle": 0,
"id": "MISC_ESTRADE_9X3",
"x": 58.208,
"y": -1.316
},
"block_6": {
"angle": 180,
"id": "STONE_BLOCK_2X2",
"x": 54.26,
"y": -21.602
},
"block_7": {
"angle": 359.985,
"id": "WOOD_BLOCK_2X1",
"x": 54.023,
"y": -12.291
},
"block_8": {
"angle": 90,
"id": "WOOD_BLOCK_2X1",
"x": 45.78,
"y": -3.658
},
"block_9": {
"angle": 90,
"id": "WOOD_BLOCK_2X1",
"x": 61.852,
"y": -3.658
}
}
};
},
dummy: null
};
window.XMLHttpRequest = FakeXMLHttpRequest;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment