Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

artpacks

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

artpacks - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

58

demo.js
// Generated by CoffeeScript 1.7.0
(function() {
var container, createArtPacks, dragleave, dragover, drop, packs, showControls, showInfo, showSounds, showTextures, urls;
var container, createArtPacks, dragleave, dragover, drop, packs, show, showControls, showInfo, showSounds, showTextures, urls;
createArtPacks = require('./');
urls = ['https://dl.dropboxusercontent.com/u/258156216/artpacks/ProgrammerArt-2.1-dev-ResourcePack-20140116.zip', 'invalid.zip', 'README.md'];
urls = ['https://dl.dropboxusercontent.com/u/258156216/artpacks/ProgrammerArt-2.2-dev-ResourcePack-20140308.zip', 'invalid.zip', 'README.md'];

@@ -28,20 +28,36 @@ container = document.createElement('div');

showTextures = function() {
var img, name, url, _i, _len, _ref, _results;
_ref = ['dirt', 'blocks/dirt', 'i/stick', 'items/stick', 'misc/shadow', 'minecraft:dirt', 'water_flow', 'invalid'];
var name, _i, _len, _ref, _results;
_ref = ['dirt', 'blocks/dirt', 'i/stick', 'items/stick', 'misc/shadow', 'minecraft:dirt', 'grass_top', 'water_flow', 'invalid'];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
container.appendChild(document.createTextNode(name + ' = '));
url = packs.getTexture(name);
if (url == null) {
container.appendChild(document.createTextNode('(not found)'));
_results.push(show(name));
}
return _results;
};
show = function(name) {
return packs.getTextureImage(name, function(img) {
var im, _i, _len, _results;
if (Array.isArray(img)) {
container.appendChild(document.createTextNode(name + (" = (animated " + img.length + ") ")));
_results = [];
for (_i = 0, _len = img.length; _i < _len; _i++) {
im = img[_i];
im.title = name;
container.appendChild(im);
_results.push(container.appendChild(document.createTextNode(', ')));
}
return _results;
} else {
img = document.createElement('img');
img.src = url;
container.appendChild(document.createTextNode(name + ' = '));
img.title = name;
container.appendChild(img);
return container.appendChild(document.createElement('br'));
}
_results.push(container.appendChild(document.createElement('br')));
}
return _results;
}, function(err) {
container.appendChild(document.createTextNode(name + ' = '));
container.appendChild(document.createTextNode('(not found)'));
return container.appendChild(document.createElement('br'));
});
};

@@ -73,11 +89,12 @@

showControls = function() {
var audio, img, input, showSample;
var audio, controls, img, input, showSample;
controls = document.createElement('div');
input = document.createElement('input');
input.setAttribute('id', 'input');
container.appendChild(input);
container.appendChild(document.createTextNode(' = '));
controls.appendChild(input);
controls.appendChild(document.createTextNode(' = '));
img = document.createElement('img');
img.setAttribute('id', 'outputImg');
img.style.visibility = 'hidden';
container.appendChild(img);
controls.appendChild(img);
audio = document.createElement('audio');

@@ -87,3 +104,3 @@ audio.setAttribute('id', 'outputAudio');

audio.style.visibility = 'hidden';
container.appendChild(audio);
controls.appendChild(audio);
showSample = function() {

@@ -109,2 +126,3 @@ var url;

input.value = 'stone';
container.appendChild(controls);
return showSample();

@@ -123,3 +141,3 @@ };

container.appendChild(document.createElement('br'));
container.appendChild(document.createTextNode('Drop a pack here to load (hold shift to append), or enter a name in text box below to lookup:'));
container.appendChild(document.createTextNode('Drop a pack here to load (hold shift to replace), or enter a name in text box below to lookup:'));
container.appendChild(document.createElement('br'));

@@ -168,3 +186,3 @@ return container.appendChild(document.createElement('br'));

arrayBuffer = readEvent.currentTarget.result;
if (!mouseEvent.shiftKey) {
if (mouseEvent.shiftKey) {
packs.clear();

@@ -171,0 +189,0 @@ }

// Generated by CoffeeScript 1.7.0
(function() {
var ArtPackArchive, ArtPacks, Buffer, EventEmitter, ZIP, binaryXHR, fs, path, splitNamespace, touchup,
var ArtPackArchive, ArtPacks, Buffer, EventEmitter, ZIP, arrayBufferToString, binaryXHR, fs, getFrames, getPixels, graycolorize, path, savePixels, splitNamespace,
__hasProp = {}.hasOwnProperty,

@@ -19,4 +19,14 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

touchup = require('touchup');
getFrames = require('mcmeta');
getPixels = require('get-pixels');
savePixels = require('save-pixels');
graycolorize = require('graycolorize');
arrayBufferToString = function(arrayBuffer) {
return String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
};
ArtPacks = (function(_super) {

@@ -30,2 +40,6 @@ __extends(ArtPacks, _super);

this.blobURLs = {};
this.shouldColorize = {
'grass_top': true,
'leaves_oak': true
};
this.setMaxListeners(0);

@@ -46,2 +60,3 @@ for (_i = 0, _len = packs.length; _i < _len; _i++) {

this.packs.push(new ArtPackArchive(rawZipArchiveData, name != null ? name : "(" + rawZipArchiveData.byteLength + " raw bytes)"));
this.refresh();
this.emit('loadedRaw', rawZipArchiveData);

@@ -72,2 +87,3 @@ return this.emit('loadedAll');

_this.packs[packIndex] = new ArtPackArchive(packData, url);
_this.refresh();
} catch (_error) {

@@ -90,6 +106,39 @@ e = _error;

this.emit('loadedAll');
return this.packs.push(pack);
this.packs.push(pack);
return this.refresh();
}
};
ArtPacks.prototype.swap = function(i, j) {
var temp;
if (i === j) {
return;
}
temp = this.packs[i];
this.packs[i] = this.packs[j];
this.packs[j] = temp;
return this.refresh();
};
ArtPacks.prototype.colorize = function(img, onload, onerror) {
return getPixels(img.src, function(err, pixels) {
var img2;
if (err) {
return onerror(err, img);
}
if (this.colorMap == null) {
this.colorMap = graycolorize.generateMap(120 / 360, 0.7);
}
graycolorize(pixels, this.colorMap);
img2 = new Image();
img2.src = savePixels(pixels, 'canvas').toDataURL();
img2.onload = function() {
return onload(img2);
};
return img2.onerror = function(err) {
return onerror(err, img2);
};
});
};
ArtPacks.prototype.getTextureImage = function(name, onload, onerror) {

@@ -107,18 +156,38 @@ var img, load;

img.onload = function() {
var destH, destW, frameImg, frameURL;
var json;
if (_this.shouldColorize[name]) {
return _this.colorize(img, onload, onerror);
}
if (img.height === img.width) {
return onload(img);
} else {
destW = destH = img.width;
console.log('extracting animation frame for', name);
frameURL = touchup.crop(img, 0, 0, img.width - destW, img.height - destH);
frameImg = new Image();
frameImg.onload = function() {
console.log('extracted animation frame', name, frameImg.width, frameImg.height, 'from', img.width, img.height);
return onload(frameImg);
};
frameImg.onerror = function(err) {
return onerror(err, frameImg);
};
return frameImg.src = frameURL;
json = _this.getMeta(name, 'textures');
console.log('.mcmeta=', json);
return getPixels(img.src, function(err, pixels) {
var frameImgs, frames, loaded;
if (err) {
return onerror(err, img);
}
frames = getFrames(pixels, json);
loaded = 0;
frameImgs = [];
return frames.forEach(function(frame) {
var frameImg;
frameImg = new Image();
frameImg.src = frame.image;
frameImg.onerror = function(err) {
return onerror(err, img, frameImg);
};
return frameImg.onload = function() {
frameImgs.push(frameImg);
if (frameImgs.length === frames.length) {
if (frameImgs.length === 1) {
return onload(frameImgs[0]);
} else {
return onload(frameImgs);
}
}
};
});
});
}

@@ -163,3 +232,3 @@ };

var blob, pack, _i, _len, _ref;
_ref = this.packs;
_ref = this.packs.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {

@@ -178,2 +247,30 @@ pack = _ref[_i];

ArtPacks.prototype.getArrayBuffer = function(name, type, isMeta) {
var arrayBuffer, pack, _i, _len, _ref;
_ref = this.packs.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
pack = _ref[_i];
if (!pack) {
continue;
}
arrayBuffer = pack.getArrayBuffer(name, type, isMeta);
if (arrayBuffer != null) {
return arrayBuffer;
}
}
return void 0;
};
ArtPacks.prototype.getMeta = function(name, type) {
var arrayBuffer, decodedString, encodedString, json;
arrayBuffer = this.getArrayBuffer(name, type, true);
if (arrayBuffer == null) {
return void 0;
}
encodedString = arrayBufferToString(arrayBuffer);
decodedString = decodeURIComponent(escape(encodedString));
json = JSON.parse(decodedString);
return json;
};
ArtPacks.prototype.refresh = function() {

@@ -186,3 +283,4 @@ var url, _i, _len, _ref;

}
return this.blobURLs = [];
this.blobURLs = [];
return this.emit('refresh');
};

@@ -198,3 +296,3 @@

ret = [];
_ref = this.packs;
_ref = this.packs.slice(0).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {

@@ -303,5 +401,11 @@ pack = _ref[_i];

ArtPackArchive.prototype.getArrayBuffer = function(name, type) {
ArtPackArchive.prototype.getArrayBuffer = function(name, type, isMeta) {
var found, namespace, pathRP, tryPath, tryPaths, zipEntry, _i, _len;
if (isMeta == null) {
isMeta = false;
}
pathRP = this.nameToPath[type](name);
if (isMeta) {
pathRP += '.mcmeta';
}
found = false;

@@ -343,2 +447,41 @@ if (pathRP.indexOf('*') === -1) {

ArtPackArchive.prototype.getFixedPathArrayBuffer = function(path) {
var _ref;
return (_ref = this.zipEntries[path]) != null ? _ref.getData() : void 0;
};
ArtPackArchive.prototype.getPackLogo = function() {
var arrayBuffer, blob;
if (this.logoURL) {
return this.logoURL;
}
arrayBuffer = this.getFixedPathArrayBuffer('pack.png');
if (arrayBuffer != null) {
blob = new Blob([arrayBuffer], {
type: 'image/png'
});
return this.logoURL = URL.createObjectURL(blob);
} else {
return this.logoURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAEUlEQVQYV2N48uTJfxBmgDEAg3wOrbpADeoAAAAASUVORK5CYII=';
}
};
ArtPackArchive.prototype.getPackJSON = function() {
var arrayBuffer, str;
if (this.json != null) {
return this.json;
}
arrayBuffer = this.getFixedPathArrayBuffer('pack.mcmeta');
if (arrayBuffer == null) {
return {};
}
str = arrayBufferToString(arrayBuffer);
return this.json = JSON.parse(str);
};
ArtPackArchive.prototype.getDescription = function() {
var _ref, _ref1, _ref2;
return (_ref = (_ref1 = this.getPackJSON()) != null ? (_ref2 = _ref1.pack) != null ? _ref2.description : void 0 : void 0) != null ? _ref : this.name;
};
return ArtPackArchive;

@@ -345,0 +488,0 @@

{
"name": "artpacks",
"description": "cascading texture/sound artwork pack loader",
"version": "0.1.2",
"version": "0.2.0",
"repository": {

@@ -19,3 +19,6 @@ "type": "git",

"native-buffer-browserify": ">=2.0.9",
"touchup": "~0.1.2"
"mcmeta": "~0.1.0",
"get-pixels": "~1.0.1",
"save-pixels": "^0.3.0",
"graycolorize": "~0.1.1"
},

@@ -22,0 +25,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc