2
0
Эх сурвалжийг харах

add missing documentation

jomo 9 жил өмнө
parent
commit
96b277b806

+ 12 - 0
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;

+ 3 - 0
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();

+ 1 - 0
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

+ 3 - 2
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();

+ 3 - 0
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();

+ 1 - 0
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 || {};