diff --git a/src/renderer-process/application.js b/src/renderer-process/application.js index ba1faee1..31b1cafe 100644 --- a/src/renderer-process/application.js +++ b/src/renderer-process/application.js @@ -7,7 +7,6 @@ const electron = require('electron') const controller = require('./controller.js') const network = require('./network.js') const path = require('path') -const fs = require('fs-extra') var project @@ -118,7 +117,7 @@ exports.setBabble = function(babbling) { } // Update the hotbar button for a character -exports.updateCharacter = function(character, thumbnail) { +exports.updateCharacter = function(character, updateThumbnail) { var index = project.project.hotbar.indexOf(character.id) if (index > -1) { controller.updateCharacter(index, character) @@ -126,15 +125,8 @@ exports.updateCharacter = function(character, thumbnail) { controller.setPuppetLocal(index) } document.getElementById('char ' + index).getElementsByClassName('desc')[0].innerHTML = character.name - } - if (thumbnail) { - fs.ensureDirSync(path.join(project.assetsPath, '..', 'thumbnails')) - fs.writeFile(path.join(project.assetsPath, '..', 'thumbnails', character.id + '.png'), new Buffer(thumbnail, 'base64'), (err) => { - if (err) console.log(err) - if (index > -1) { - document.getElementById('char ' + index).style.backgroundImage = 'url(' + path.join(project.assetsPath, '..', 'thumbnails', character.id + '.png?random=' + new Date().getTime()) + ')' - } - }) + if (updateThumbnail) + document.getElementById('char ' + index).style.backgroundImage = 'url(' + path.join(project.assetsPath, '..', 'thumbnails', 'new-' + character.id + '.png?random=' + new Date().getTime()) + ')' } } diff --git a/src/renderer-process/controller.js b/src/renderer-process/controller.js index 8879f8ad..a64bc898 100644 --- a/src/renderer-process/controller.js +++ b/src/renderer-process/controller.js @@ -6,6 +6,7 @@ const editor = require('./editor.js') const network = require('./network.js') const status = require('./status.js') const Stage = require('./stage.js').Stage +const fs = require('fs-extra') const path = require('path') const url = require('url') @@ -339,7 +340,15 @@ exports.updateCharacter = function(index, character) { exports.saveCharacter = function(character, thumbnail) { project.saveCharacter(character) - application.updateCharacter(character, thumbnail) + if (thumbnail) { + fs.ensureDirSync(path.join(project.assetsPath, '..', 'thumbnails')) + fs.writeFile(path.join(project.assetsPath, '..', 'thumbnails', 'new-' + character.id + '.png'), new Buffer(thumbnail, 'base64'), (err) => { + if (err) console.log(err) + application.updateCharacter(character, true) + }) + } else { + application.updateCharacter(character) + } } exports.connect = function() { diff --git a/src/renderer-process/editor.js b/src/renderer-process/editor.js index 8970bc01..6219ddc9 100644 --- a/src/renderer-process/editor.js +++ b/src/renderer-process/editor.js @@ -702,7 +702,10 @@ function openPuppetPanel() { var selector = document.createElement('div') selector.id = project.characters[characters[j]].name.toLowerCase() selector.className = "char" - selector.style.backgroundImage = 'url(' + path.join(project.assetsPath, '..', 'thumbnails', characters[j] + '.png?random=' + new Date().getTime()) + ')' + if (fs.existsSync(path.join(project.assetsPath, '..', 'thumbnails', 'new-' + characters[j] + '.png'))) + selector.style.backgroundImage = 'url(' + path.join(project.assetsPath, '..', 'thumbnails', 'new-' + characters[j] + '.png?random=' + new Date().getTime()) + ')' + else + selector.style.backgroundImage = 'url(' + path.join(project.assetsPath, '..', 'thumbnails', characters[j] + '.png?random=' + new Date().getTime()) + ')' charList.appendChild(selector) selector.innerHTML = '
' + project.characters[characters[j]].name + '
' selector.charid = characters[j] diff --git a/src/renderer-process/project.js b/src/renderer-process/project.js index 8611978e..121ad107 100644 --- a/src/renderer-process/project.js +++ b/src/renderer-process/project.js @@ -58,8 +58,12 @@ module.exports = exports = remote.getGlobal('project').project = { fs.writeJson(settings.settings.openProject, this.project) for (var i = 0; i < this.project.assets.length; i++) fs.writeJson(path.join(settings.settings.openProject, '..', 'assets', this.project.assets[i].location), this.assets[this.project.assets[i].name]) - for (var i = 0; i < this.project.characters.length; i++) + for (var i = 0; i < this.project.characters.length; i++) { fs.writeJson(path.join(settings.settings.openProject, '..', 'characters', this.project.characters[i].location), this.characters[this.project.characters[i].id]) + if (fs.existsSync(path.join(this.assetsPath, '..', 'thumbnails', 'new-' + this.project.characters[i].id + '.png'))) + fs.renameSync(path.join(this.assetsPath, '..', 'thumbnails', 'new-' + this.project.characters[i].id + '.png'), + path.join(this.assetsPath, '..', 'thumbnails', this.project.characters[i].id + '.png')) + } this.oldProject = JSON.stringify(this.project) this.oldAssets = JSON.stringify(this.assets) this.oldCharacters = JSON.stringify(this.characters)