Skip to content

Instantly share code, notes, and snippets.

@leizhao4
Last active January 4, 2016 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leizhao4/8564965 to your computer and use it in GitHub Desktop.
Save leizhao4/8564965 to your computer and use it in GitHub Desktop.
For Uncovery Minecraft 2D Map
(function () {
// Please update this part
var connectedLots = [
"c22", "l11", "m11", "m15", "n10", "n11", "o11", "o12", "o13", "o14", "p11", "p12", "p13",
"p14", "p15", "p16", "q11", "q16", "q17", "q18", "q19", "r11", "r17", "r19"
];
var underConstructionLots = [
"k11", "k12", "k13", "l12", "l13", "p17", "r10"
];
var pendingLots = [
"c18", "c23", "f14", "k17", "l14", "l22", "l23", "l24", "m14", "m15", "m16", "m22", "m23",
"m24", "n22", "n23", "n24", "p28", "p29", "q13", "q29", "q30", "r9", "r13", "r29", "r30",
"s13", "s14", "s15", "s17", "s18", "t7", "t8", "t13", "t14", "t15", "t17", "t18", "t24",
"t25", "u7", "u8", "u17", "u18", "u19", "u24", "u25", "x18", "y18", "y19", "aa17", "ac14",
"ad10"
];
var mapUrl = "http://uncovery.me/admin/index.php?function=create_map";
var prepare = function () {
window.renderMode = 0;
window.update_positions = function () {
$("img.marker").remove();
};
$("div:first").remove();
$("#outer_box").css({ top: 0, left: 0, color: "rgba(0, 0, 0, 0)" });
$.each($(".size124_124"), function (i, l) {
var lot = $(l);
lot.data({
html: lot.html(),
top: parseInt(lot.css("top")) || 0,
left: parseInt(lot.css("left")) || 0,
color: lot.css("color"),
bgcolor: lot.css("background-color"),
bcolor: lot.css("border-color"),
lheight: lot.css("line-height")
});
});
};
var setMode = function (mode) {
// Render Modes:
// 0 - Original
// 1 - Compact (32x32 lots)
// 2 - Full (64x64 lots with player names)
if (mode !== 1 && mode !== 2) {
$("#image_box").show();
$(".size124_124").width(128).height(128).css("text-align", "left");
$.each($(".size124_124"), function (i, l) {
var lot = $(l);
lot.html(lot.data("html")).css({
top: lot.data("top") + "px",
left: lot.data("left") + "px",
color: lot.data("color"),
"background-color": lot.data("bgcolor"),
"border-color": lot.data("bcolor"),
"line-height": lot.data("lheight")
});
});
$("#EMP_Q17").css("font-weight", "inherit");
} else {
var lotSize = (mode === 1) ? 32 : 64;
$("#image_box").hide();
$(".size124_124").width(lotSize).height(lotSize).css({
"text-align": "center", "border-color": "#ccc"
});
$.each($(".size124_124"), function (i, l) {
var lot = $(l);
lot.css({
top: (lot.data("top") / 128 * lotSize) + "px",
left: (lot.data("left") / 128 * lotSize) + "px",
"line-height": (mode === 1) ? "34px" : "inherit"
});
lot.html((mode === 1) ? lot.attr("id").substr(4, 3) : lot.data("html"));
if (lot.hasClass("whiteborder")) {
lot.css({ "background-color": "#ddd", "color": "#aaa" });
} else if (lot.hasClass("blackborder")) {
lot.css({ "background-color": "#999", "color": "#555" });
} else if (lot.hasClass("redborder")) {
lot.css({ "background-color": "#faa", "color": "#f33" });
} else if (lot.hasClass("yellowborder")) {
lot.css({ "background-color": "#cb9", "color": "#773" });
}
});
$(".coords").remove();
$(".innertext").removeClass("innertext").css({
"background": "inherit", padding: "2px"
});
$(".Owner").removeClass("Owner");
$(".user").removeClass("user");
$("#EMP_Q17").text("Spawn").css("font-weight", "bold");
if (mode === 2) {
$("#EMP_Q17").css("line-height", "64px");
}
$.each(pendingLots, function (i, lotName) {
var lot = $("#EMP_" + lotName.toUpperCase());
if (!lot.hasClass("whiteborder")) {
lot.css({ "background-color": "#7f7", "color": "#000" });
}
});
$.each(underConstructionLots, function (i, lotName) {
var lot = $("#EMP_" + lotName.toUpperCase());
if (!lot.hasClass("whiteborder")) {
lot.css({ "background-color": "#3b3", "color": "#ffe" });
}
});
$.each(connectedLots, function (i, lotName) {
var lot = $("#EMP_" + lotName.toUpperCase());
if (!lot.hasClass("whiteborder")) {
lot.css({ "background-color": "#07f", "color": "#fff" });
}
});
}
};
var block = function (callback) {
window.blocker = $("<div />").css({
position: "absolute", top: 0, left: 0, width: document.width, height: document.height,
"z-index": 1000, "background-color": "rgba(0, 0, 0, 0.9)"
}).fadeIn(200, callback).appendTo("body");
var message = $("<div>Please wait...</div>").css({
position: "absolute", color: "white", "font": "32px sans-serif"
}).appendTo(window.blocker);
message.css({
top: (window.pageYOffset + window.innerHeight * .4) + "px",
left: (window.pageXOffset + (window.innerWidth - message.width()) / 2) + "px"
});
};
var unblock = function () {
var blocker = window.blocker;
if (blocker) {
blocker.fadeOut(200, function () {
if (blocker) {
blocker.remove();
}
});
window.blocker = null;
}
};
if (window.location.href !== mapUrl) {
if (window.$) {
block(function () {
window.location.href = mapUrl;
});
} else {
document.body.innerHTML = "Please wait...";
window.location.href = mapUrl;
}
} else {
block(function () {
if (window.renderMode === undefined) {
prepare();
}
window.renderMode = (window.renderMode + 1) % 3;
setMode(window.renderMode);
unblock();
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment