update code docs

This commit is contained in:
Jake 2014-12-20 15:44:38 -06:00
parent 573278b035
commit a2f40045a9
3 changed files with 17 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// Skin locations are based on the work of Confuser // Skin locations are based on the work of Confuser, with 1.8 updates by Jake0oo0
// https://github.com/confuser/serverless-mc-skin-viewer // https://github.com/confuser/serverless-mc-skin-viewer
// Permission to use & distribute https://github.com/confuser/serverless-mc-skin-viewer/blob/master/LICENSE // Permission to use & distribute https://github.com/confuser/serverless-mc-skin-viewer/blob/master/LICENSE
@ -126,6 +126,10 @@ exp.draw_body = function(skin_canvas, model_ctx, scale) {
} }
}; };
// sets up the necessary components to draw the skin model
// uses the +img+ skin from the +uuid+ with options of drawing
// the +helm+ and the +body+
// callback contains error, image buffer
exp.draw_model = function(uuid, img, scale, helm, body, callback) { exp.draw_model = function(uuid, img, scale, helm, body, callback) {
var image = new Image(); var image = new Image();
@ -168,6 +172,8 @@ exp.draw_model = function(uuid, img, scale, helm, body, callback) {
image.src = img; image.src = img;
}; };
// helper method to open a render from +renderpath+
// callback contains error, image buffer
exp.open_render = function(renderpath, callback) { exp.open_render = function(renderpath, callback) {
fs.readFile(renderpath, function (err, buf) { fs.readFile(renderpath, function (err, buf) {
if (err) { if (err) {
@ -177,6 +183,8 @@ exp.open_render = function(renderpath, callback) {
}); });
}; };
// scales an image from the +imagedata+ onto the +context+
// scaled by a factor of +scale+ with options +d_x+ and +d_y+
function scale_image(imageData, context, d_x, d_y, scale) { function scale_image(imageData, context, d_x, d_y, scale) {
var width = imageData.width; var width = imageData.width;
var height = imageData.height; var height = imageData.height;

View File

@ -93,6 +93,8 @@ exp.default_skin = function(uuid) {
} }
}; };
// helper method for opening a skin file from +skinpath+
// callback contains error, image buffer
exp.open_skin = function(skinpath, callback) { exp.open_skin = function(skinpath, callback) {
fs.readFile(skinpath, function (err, buf) { fs.readFile(skinpath, function (err, buf) {
if (err) { if (err) {

View File

@ -77,6 +77,9 @@ router.get('/:type/:uuid.:ext?', function(req, res) {
handle_default(500, status); handle_default(500, status);
} }
// default alex/steve images can be rendered, but
// custom images will not be
function handle_default(http_status, img_status) { function handle_default(http_status, img_status) {
if (def && def != "steve" && def != "alex") { if (def && def != "steve" && def != "alex") {
res.writeHead(301, { res.writeHead(301, {
@ -91,8 +94,10 @@ router.get('/:type/:uuid.:ext?', function(req, res) {
def = def || skins.default_skin(uuid); def = def || skins.default_skin(uuid);
fs.readFile("public/images/" + def + "_skin.png", function (err, buf) { fs.readFile("public/images/" + def + "_skin.png", function (err, buf) {
if (err) { if (err) {
logging.error("error rendering default image: " + err); // errored while loading the default image, continuing with null image
logging.error("error loading default render image: " + err);
} }
// we render the default skins, but not custom images
renders.draw_model(uuid, buf, scale, helm, body, function(err, def_img) { renders.draw_model(uuid, buf, scale, helm, body, function(err, def_img) {
if (err) { if (err) {
logging.log("error while rendering default image: " + err); logging.log("error while rendering default image: " + err);