Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Fixed #12
Browse files Browse the repository at this point in the history
  • Loading branch information
thepaperpilot committed May 9, 2017
1 parent 721f14b commit 2e0522c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
14 changes: 3 additions & 11 deletions src/renderer-process/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -118,23 +117,16 @@ 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)
if (('' + document.getElementById('char ' + index).className).indexOf('selected') > -1) {
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()) + ')'
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/renderer-process/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion src/renderer-process/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="desc">' + project.characters[characters[j]].name + '</div>'
selector.charid = characters[j]
Expand Down
6 changes: 5 additions & 1 deletion src/renderer-process/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2e0522c

Please sign in to comment.