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 @@ } |
183
index.js
// 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38898
612
7
+ Addedget-pixels@~1.0.1
+ Addedgraycolorize@~0.1.1
+ Addedmcmeta@~0.1.0
+ Addedsave-pixels@^0.3.0
+ Addedacorn@7.4.1(transitive)
+ Addedalign-text@0.1.4(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcwise@0.3.41.0.10(transitive)
+ Addedcwise-compiler@0.0.01.1.3(transitive)
+ Addedcwise-parser@0.0.11.0.3(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addedescodegen@0.0.281.3.3(transitive)
+ Addedesprima@1.0.41.1.11.2.5(transitive)
+ Addedestraverse@1.3.21.5.1(transitive)
+ Addedesutils@1.0.0(transitive)
+ Addedfalafel@2.2.5(transitive)
+ Addedget-pixels@1.0.1(transitive)
+ Addedgraycolorize@0.1.2(transitive)
+ Addedhas@1.0.4(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addediota-array@1.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedisarray@0.0.11.0.02.0.5(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedmcmeta@0.1.1(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedndarray@1.0.19(transitive)
+ Addedndarray-pack@1.0.0(transitive)
+ Addedobject-inspect@0.4.0(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedonecolor@2.5.0(transitive)
+ Addedpngjs@0.4.0(transitive)
+ Addedpngparse@1.1.4(transitive)
+ Addedppm@0.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedquote-stream@0.0.0(transitive)
+ Addedreadable-stream@1.0.341.1.142.3.8(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsave-pixels@0.3.0(transitive)
+ Addedshallow-copy@0.0.1(transitive)
+ Addedsource-map@0.1.430.5.7(transitive)
+ Addedstatic-eval@0.2.4(transitive)
+ Addedstatic-module@1.5.0(transitive)
+ Addedstring_decoder@0.10.311.1.1(transitive)
+ Addedthrough@2.2.72.3.8(transitive)
+ Addedthrough2@0.4.2(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addeduglify-js@2.8.29(transitive)
+ Addeduglify-to-browserify@1.0.2(transitive)
+ Addeduniq@0.0.21.0.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwindow-size@0.1.0(transitive)
+ Addedwordwrap@0.0.2(transitive)
+ Addedxtend@2.1.2(transitive)
+ Addedyargs@3.10.0(transitive)
- Removedtouchup@~0.1.2
- Removedtouchup@0.1.2(transitive)