diff --git a/lib/renders.js b/lib/renders.js index 9fe1b9c..cc22092 100644 --- a/lib/renders.js +++ b/lib/renders.js @@ -26,6 +26,8 @@ function removeTransparency(canvas) { return canvas; } + +// checks if the given +canvas+ has any pixel that is not fully opaque function hasTransparency(canvas) { var ctx = canvas.getContext("2d"); var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data; @@ -38,6 +40,8 @@ function hasTransparency(canvas) { return false; } +// resize the +src+ canvas by +scale+ +// returns a new canvas function resize(src, scale) { var dst = new Canvas(); dst.width = scale * src.width; @@ -51,6 +55,8 @@ function resize(src, scale) { return dst; } +// get a rectangular part of the +src+ canvas +// the returned canvas is scaled by factor +scale+ function getPart(src, x, y, width, height, scale) { var dst = new Canvas(); dst.width = scale * width; @@ -64,6 +70,7 @@ function getPart(src, x, y, width, height, scale) { return dst; } +// flip the +src+ canvas horizontally function flip(src) { var dst = new Canvas(); dst.width = src.width; @@ -78,6 +85,11 @@ function flip(src) { var skew_a = 26 / 45; // 0.57777777 var skew_b = skew_a * 2; // 1.15555555 +// renders a player model with the given skin +img+ and +scale+ +// +overlay+ - wether the extra skin layer is rendered +// +is_body+ - false for head only +// +slim+ - wether the player has a slim skin model +// callback: error, image buffer exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) { var canvas = new Canvas(); canvas.width = scale * 20; diff --git a/lib/routes/avatars.js b/lib/routes/avatars.js index 9541faf..56c954c 100644 --- a/lib/routes/avatars.js +++ b/lib/routes/avatars.js @@ -5,6 +5,9 @@ var cache = require("../cache"); var path = require("path"); var url = require("url"); +// handle the appropriate 'default=' response +// uses either mhf_steve or mhf_alex (based on +userId+) if no +def+ given +// callback: response object function handle_default(img_status, userId, size, def, req, err, callback) { def = def || skins.default_skin(userId); var defname = def.toLowerCase(); diff --git a/lib/routes/index.js b/lib/routes/index.js index fc13275..6c22a04 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -15,6 +15,7 @@ function compile() { compile(); +// GET index request module.exports = function(req, callback) { if (config.server.debug_enabled) { // allow changes without reloading diff --git a/lib/routes/renders.js b/lib/routes/renders.js index 8295535..ff742e0 100644 --- a/lib/routes/renders.js +++ b/lib/routes/renders.js @@ -8,8 +8,9 @@ var path = require("path"); var url = require("url"); var fs = require("fs"); -// valid types: head, body -// overlay is query param +// handle the appropriate 'default=' response +// uses either mhf_steve or mhf_alex (based on +userId+) if no +def+ given +// callback: response object function handle_default(rid, scale, overlay, body, img_status, userId, size, def, req, err, callback) { def = def || skins.default_skin(userId); var defname = def.toLowerCase(); diff --git a/lib/routes/skins.js b/lib/routes/skins.js index eeb49ca..fb1ae6f 100644 --- a/lib/routes/skins.js +++ b/lib/routes/skins.js @@ -5,6 +5,9 @@ var path = require("path"); var lwip = require("lwip"); var url = require("url"); +// handle the appropriate 'default=' response +// uses either mhf_steve or mhf_alex (based on +userId+) if no +def+ given +// callback: response object function handle_default(img_status, userId, def, req, err, callback) { def = def || skins.default_skin(userId); var defname = def.toLowerCase(); diff --git a/lib/server.js b/lib/server.js index c5c3c80..dad6ba1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -56,6 +56,7 @@ function path_list(pathname) { return list; } +// handles the +req+ by routing to the request to the appropriate module function requestHandler(req, res) { req.url = url.parse(req.url, true); req.url.query = req.url.query || {};