save-panel : added piskel descriptor
This commit is contained in:
parent
b11b16b427
commit
b77f7057d7
15 changed files with 103 additions and 56 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
.row {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.textfield {
|
.textfield {
|
||||||
background : black;
|
background : black;
|
||||||
border : 1px solid #888;
|
border : 1px solid #888;
|
||||||
|
|
|
@ -51,6 +51,10 @@
|
||||||
text-shadow: 1px 1px #000;
|
text-shadow: 1px 1px #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-section .button {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.settings-title {
|
.settings-title {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
@ -61,6 +65,10 @@
|
||||||
|
|
||||||
.settings-item {}
|
.settings-item {}
|
||||||
|
|
||||||
|
.settings-form-section {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.background-picker-wrapper {
|
.background-picker-wrapper {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 10px 5px 20px 5px;
|
padding: 10px 5px 20px 5px;
|
||||||
|
|
27
js/app.js
27
js/app.js
|
@ -14,8 +14,9 @@
|
||||||
this.shortcutService.init();
|
this.shortcutService.init();
|
||||||
|
|
||||||
var size = this.readSizeFromURL_();
|
var size = this.readSizeFromURL_();
|
||||||
var piskel = new pskl.model.Piskel(size.width, size.height);
|
|
||||||
piskel.setDescriptor("New Piskel", "Some text ...");
|
var descriptor = new pskl.model.piskel.Descriptor('New Piskel', '');
|
||||||
|
var piskel = new pskl.model.Piskel(size.width, size.height, descriptor);
|
||||||
|
|
||||||
var layer = new pskl.model.Layer("Layer 1");
|
var layer = new pskl.model.Layer("Layer 1");
|
||||||
var frame = new pskl.model.Frame(size.width, size.height);
|
var frame = new pskl.model.Frame(size.width, size.height);
|
||||||
|
@ -65,7 +66,6 @@
|
||||||
this.imageUploadService = new pskl.service.ImageUploadService();
|
this.imageUploadService = new pskl.service.ImageUploadService();
|
||||||
this.imageUploadService.init();
|
this.imageUploadService.init();
|
||||||
|
|
||||||
|
|
||||||
this.cheatsheetService = new pskl.service.keyboard.CheatsheetService();
|
this.cheatsheetService = new pskl.service.keyboard.CheatsheetService();
|
||||||
this.cheatsheetService.init();
|
this.cheatsheetService.init();
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
drawingLoop.addCallback(this.render, this);
|
drawingLoop.addCallback(this.render, this);
|
||||||
drawingLoop.start();
|
drawingLoop.start();
|
||||||
|
|
||||||
this.initBootstrapTooltips_();
|
this.initTooltips_();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when piskel is running in static mode (no back end needed).
|
* True when piskel is running in static mode (no back end needed).
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initBootstrapTooltips_ : function () {
|
initTooltips_ : function () {
|
||||||
$('body').tooltip({
|
$('body').tooltip({
|
||||||
selector: '[rel=tooltip]'
|
selector: '[rel=tooltip]'
|
||||||
});
|
});
|
||||||
|
@ -123,8 +123,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
readSizeFromURL_ : function () {
|
readSizeFromURL_ : function () {
|
||||||
var sizeParam = this.readUrlParameter_("size"),
|
var sizeParam = this.readUrlParameter_("size");
|
||||||
size;
|
var size;
|
||||||
// parameter expected as size=64x48 => size=widthxheight
|
// parameter expected as size=64x48 => size=widthxheight
|
||||||
var parts = sizeParam.split("x");
|
var parts = sizeParam.split("x");
|
||||||
if (parts && parts.length == 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
|
if (parts && parts.length == 2 && !isNaN(parts[0]) && !isNaN(parts[1])) {
|
||||||
|
@ -149,13 +149,12 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
readUrlParameter_ : function (paramName) {
|
readUrlParameter_ : function (paramName) {
|
||||||
var searchString = window.location.search.substring(1),
|
var searchString = window.location.search.substring(1);
|
||||||
i, val, params = searchString.split("&");
|
var params = searchString.split("&");
|
||||||
|
for (var i = 0; i < params.length; i++) {
|
||||||
for (i = 0; i < params.length; i++) {
|
var param = params[i].split("=");
|
||||||
val = params[i].split("=");
|
if (param[0] == paramName) {
|
||||||
if (val[0] == paramName) {
|
return window.unescape(param[1]);
|
||||||
return window.unescape(val[1]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -154,7 +154,9 @@
|
||||||
var frame = pskl.utils.FrameUtils.createFromImage(image);
|
var frame = pskl.utils.FrameUtils.createFromImage(image);
|
||||||
|
|
||||||
var layer = pskl.model.Layer.fromFrames('Layer 1', [frame]);
|
var layer = pskl.model.Layer.fromFrames('Layer 1', [frame]);
|
||||||
var piskel = pskl.model.Piskel.fromLayers([layer]);
|
|
||||||
|
var descriptor = new pskl.model.piskel.Descriptor('Imported piskel', '');
|
||||||
|
var piskel = pskl.model.Piskel.fromLayers([layer], descriptor);
|
||||||
|
|
||||||
pskl.app.piskelController.setPiskel(piskel);
|
pskl.app.piskelController.setPiskel(piskel);
|
||||||
pskl.app.animationController.setFPS(Constants.DEFAULT.FPS);
|
pskl.app.animationController.setFPS(Constants.DEFAULT.FPS);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(function () {
|
(function () {
|
||||||
var ns = $.namespace("pskl.controller.settings");
|
var ns = $.namespace('pskl.controller.settings');
|
||||||
|
|
||||||
ns.SaveController = function (piskelController) {
|
ns.SaveController = function (piskelController) {
|
||||||
this.piskelController = piskelController;
|
this.piskelController = piskelController;
|
||||||
|
@ -9,10 +9,12 @@
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
ns.SaveController.prototype.init = function () {
|
ns.SaveController.prototype.init = function () {
|
||||||
this.titleInput = document.getElementById("save-title");
|
this.titleInput = $('#save-title');
|
||||||
this.descriptionInput = document.getElementById("save-description");
|
this.descriptionInput = $('#save-description');
|
||||||
|
this.saveForm = $('form[name=save-form]');
|
||||||
|
|
||||||
this.titleInput.value = this.piskelController.piskel.getDescriptor().name;
|
var descriptor = this.piskelController.piskel.getDescriptor();
|
||||||
this.descriptionInput.value = this.piskelController.piskel.getDescriptor().description;
|
this.titleInput.val(descriptor.name);
|
||||||
|
this.descriptionInput.val(descriptor.description);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
|
@ -8,8 +8,8 @@
|
||||||
* @param {String} name
|
* @param {String} name
|
||||||
* @param {String} description
|
* @param {String} description
|
||||||
*/
|
*/
|
||||||
ns.Piskel = function (width, height) {
|
ns.Piskel = function (width, height, descriptor) {
|
||||||
if (width && height) {
|
if (width && height && descriptor) {
|
||||||
/** @type {Array} */
|
/** @type {Array} */
|
||||||
this.layers = [];
|
this.layers = [];
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
this.descriptor = null;
|
this.descriptor = descriptor;
|
||||||
} else {
|
} else {
|
||||||
throw 'Missing arguments in Piskel constructor : ' + Array.prototype.join.call(arguments, ",");
|
throw 'Missing arguments in Piskel constructor : ' + Array.prototype.join.call(arguments, ",");
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@
|
||||||
* @param {Array<pskl.model.Layer>} layers
|
* @param {Array<pskl.model.Layer>} layers
|
||||||
* @return {pskl.model.Piskel}
|
* @return {pskl.model.Piskel}
|
||||||
*/
|
*/
|
||||||
ns.Piskel.fromLayers = function (layers) {
|
ns.Piskel.fromLayers = function (layers, descriptor) {
|
||||||
var piskel = null;
|
var piskel = null;
|
||||||
if (layers.length > 0 && layers[0].length() > 0) {
|
if (layers.length > 0 && layers[0].length() > 0) {
|
||||||
var sampleFrame = layers[0].getFrameAt(0);
|
var sampleFrame = layers[0].getFrameAt(0);
|
||||||
piskel = new pskl.model.Piskel(sampleFrame.getWidth(), sampleFrame.getHeight());
|
piskel = new pskl.model.Piskel(sampleFrame.getWidth(), sampleFrame.getHeight(), descriptor);
|
||||||
layers.forEach(piskel.addLayer.bind(piskel));
|
layers.forEach(piskel.addLayer.bind(piskel));
|
||||||
} else {
|
} else {
|
||||||
throw 'Piskel.fromLayers expects array of non empty pskl.model.Layer as first argument';
|
throw 'Piskel.fromLayers expects array of non empty pskl.model.Layer as first argument';
|
||||||
|
@ -104,11 +104,8 @@
|
||||||
return this.descriptor;
|
return this.descriptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Piskel.prototype.setDescriptor = function (name, desc) {
|
ns.Piskel.prototype.setDescriptor = function (name, description) {
|
||||||
this.descriptor = {
|
this.descriptor = new pskl.model.piskel.Descriptor(name, description);
|
||||||
name : name,
|
|
||||||
description : desc
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
8
js/model/piskel/Descriptor.js
Normal file
8
js/model/piskel/Descriptor.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
(function () {
|
||||||
|
var ns = $.namespace('pskl.model.piskel');
|
||||||
|
|
||||||
|
ns.Descriptor = function (name, description) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
};
|
||||||
|
})();
|
|
@ -6,6 +6,7 @@
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
this.previousTime = 0;
|
this.previousTime = 0;
|
||||||
this.callbacks = [];
|
this.callbacks = [];
|
||||||
|
this.i = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingLoop.prototype.addCallback = function (callback, scope, args) {
|
ns.DrawingLoop.prototype.addCallback = function (callback, scope, args) {
|
||||||
|
@ -33,7 +34,10 @@
|
||||||
ns.DrawingLoop.prototype.loop_ = function () {
|
ns.DrawingLoop.prototype.loop_ = function () {
|
||||||
var currentTime = Date.now();
|
var currentTime = Date.now();
|
||||||
var delta = currentTime - this.previousTime;
|
var delta = currentTime - this.previousTime;
|
||||||
this.executeCallbacks_(delta);
|
this.i++;
|
||||||
|
if(this.i%2 === 0) {
|
||||||
|
this.executeCallbacks_(delta);
|
||||||
|
}
|
||||||
this.previousTime = currentTime;
|
this.previousTime = currentTime;
|
||||||
this.requestAnimationFrame.call(window, this.loop_.bind(this));
|
this.requestAnimationFrame.call(window, this.loop_.bind(this));
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
var ns = $.namespace("pskl.service");
|
var ns = $.namespace("pskl.service");
|
||||||
ns.HistoryService = function (piskelController) {
|
ns.HistoryService = function (piskelController) {
|
||||||
this.piskelController = piskelController;
|
this.piskelController = piskelController;
|
||||||
|
this.saveState__b = this.saveState.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.HistoryService.prototype.init = function () {
|
ns.HistoryService.prototype.init = function () {
|
||||||
|
|
||||||
$.subscribe(Events.TOOL_RELEASED, this.saveState.bind(this));
|
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
|
||||||
|
$.subscribe(Events.TOOL_RELEASED, this.saveState__b);
|
||||||
|
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+Z', this.undo.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+Z', this.undo.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+Y', this.redo.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+Y', this.redo.bind(this));
|
||||||
|
@ -18,12 +20,16 @@
|
||||||
|
|
||||||
ns.HistoryService.prototype.undo = function () {
|
ns.HistoryService.prototype.undo = function () {
|
||||||
this.piskelController.getCurrentFrame().loadPreviousState();
|
this.piskelController.getCurrentFrame().loadPreviousState();
|
||||||
|
$.unsubscribe(Events.PISKEL_RESET, this.saveState__b);
|
||||||
$.publish(Events.PISKEL_RESET);
|
$.publish(Events.PISKEL_RESET);
|
||||||
|
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.HistoryService.prototype.redo = function () {
|
ns.HistoryService.prototype.redo = function () {
|
||||||
this.piskelController.getCurrentFrame().loadNextState();
|
this.piskelController.getCurrentFrame().loadNextState();
|
||||||
|
$.unsubscribe(Events.PISKEL_RESET, this.saveState__b);
|
||||||
$.publish(Events.PISKEL_RESET);
|
$.publish(Events.PISKEL_RESET);
|
||||||
|
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -45,6 +45,7 @@
|
||||||
*/
|
*/
|
||||||
ns.LocalStorageService.prototype.restoreFromLocalStorage_ = function() {
|
ns.LocalStorageService.prototype.restoreFromLocalStorage_ = function() {
|
||||||
var framesheet = JSON.parse(window.localStorage.snapShot);
|
var framesheet = JSON.parse(window.localStorage.snapShot);
|
||||||
|
|
||||||
pskl.utils.serialization.Deserializer.deserialize(framesheet, function (piskel) {
|
pskl.utils.serialization.Deserializer.deserialize(framesheet, function (piskel) {
|
||||||
pskl.app.piskelController.setPiskel(piskel);
|
pskl.app.piskelController.setPiskel(piskel);
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,28 +54,36 @@
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ns.ShortcutService.prototype.onKeyUp_ = function(evt) {
|
ns.ShortcutService.prototype.onKeyUp_ = function(evt) {
|
||||||
// jquery names FTW ...
|
if (!this.isInInput_(evt)) {
|
||||||
var keycode = evt.which;
|
// jquery names FTW ...
|
||||||
var charkey = pskl.service.keyboard.KeycodeTranslator.toChar(keycode);
|
var keycode = evt.which;
|
||||||
|
var targetTagName = evt.target.nodeName.toUpperCase();
|
||||||
|
var charkey = pskl.service.keyboard.KeycodeTranslator.toChar(keycode);
|
||||||
|
|
||||||
var keyShortcuts = this.shortcuts_[charkey];
|
var keyShortcuts = this.shortcuts_[charkey];
|
||||||
if(keyShortcuts) {
|
if(keyShortcuts) {
|
||||||
var cb;
|
var cb;
|
||||||
if (this.isCtrlKeyPressed_(evt)) {
|
if (this.isCtrlKeyPressed_(evt)) {
|
||||||
cb = keyShortcuts.ctrl;
|
cb = keyShortcuts.ctrl;
|
||||||
} else if (this.isShiftKeyPressed_(evt)) {
|
} else if (this.isShiftKeyPressed_(evt)) {
|
||||||
cb = keyShortcuts.shift;
|
cb = keyShortcuts.shift;
|
||||||
} else {
|
} else {
|
||||||
cb = keyShortcuts.normal;
|
cb = keyShortcuts.normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cb) {
|
if(cb) {
|
||||||
cb(charkey);
|
cb(charkey);
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.ShortcutService.prototype.isInInput_ = function (evt) {
|
||||||
|
var targetTagName = evt.target.nodeName.toUpperCase();
|
||||||
|
return targetTagName === 'INPUT' || targetTagName === 'TEXTAREA';
|
||||||
|
};
|
||||||
|
|
||||||
ns.ShortcutService.prototype.isCtrlKeyPressed_ = function (evt) {
|
ns.ShortcutService.prototype.isCtrlKeyPressed_ = function (evt) {
|
||||||
return this.isMac_() ? evt.metaKey : evt.ctrlKey;
|
return this.isMac_() ? evt.metaKey : evt.ctrlKey;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
ns.Deserializer.prototype.deserialize = function () {
|
ns.Deserializer.prototype.deserialize = function () {
|
||||||
var data = this.data_;
|
var data = this.data_;
|
||||||
var piskelData = data.piskel;
|
var piskelData = data.piskel;
|
||||||
this.piskel_ = new pskl.model.Piskel(piskelData.width, piskelData.height);
|
|
||||||
|
var descriptor = new pskl.model.piskel.Descriptor('Deserialized piskel', '');
|
||||||
|
this.piskel_ = new pskl.model.Piskel(piskelData.width, piskelData.height, descriptor);
|
||||||
|
|
||||||
this.layersToLoad_ = piskelData.layers.length;
|
this.layersToLoad_ = piskelData.layers.length;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ exports.scripts = [
|
||||||
// Models
|
// Models
|
||||||
"js/model/Frame.js",
|
"js/model/Frame.js",
|
||||||
"js/model/Layer.js",
|
"js/model/Layer.js",
|
||||||
|
"js/model/piskel/Descriptor.js",
|
||||||
"js/model/Piskel.js",
|
"js/model/Piskel.js",
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
|
|
|
@ -2,15 +2,20 @@
|
||||||
<div class="settings-title">Save</div>
|
<div class="settings-title">Save</div>
|
||||||
<div class="settings-item">
|
<div class="settings-item">
|
||||||
<form action="" method="POST" name="save-form">
|
<form action="" method="POST" name="save-form">
|
||||||
<div class="row">
|
<div class="settings-form-section">
|
||||||
<label>Title : </label>
|
<label class="row">Title : </label>
|
||||||
|
<input id="save-title" type="text" style="width :100%;"/>
|
||||||
</div>
|
</div>
|
||||||
<input id="save-title" type="text" style="width :100%;"/>
|
<div class="settings-form-section">
|
||||||
<div class="row">
|
<label class="row">Description :</label>
|
||||||
<label>Description :</label>
|
<textarea id="save-description" style="width :100%;" placeholder="Your piskel in a few words"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="save-description" style="width :100%;"></textarea>
|
<div class="settings-form-section">
|
||||||
<input type="submit" class="button button-primary gif-upload-button" value="Save" />
|
<label class="row">
|
||||||
|
Public <input type="checkbox" value="1" name="save-public-checkbox"/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<input type="submit" class="button button-primary save-button" value="Save" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue