Fix issues with loading textures in projects/backups

Related to #695
This commit is contained in:
JannisX11 2020-08-05 16:34:31 +02:00
parent 6aa289ffc2
commit a079b16e39
3 changed files with 13 additions and 11 deletions

View File

@ -326,7 +326,7 @@ function createBackup(init) {
}
if (init || elements.length === 0) return;
var model = Codecs.project.compile({compressed: true})
var model = Codecs.project.compile({compressed: true, backup: true})
localStorage.setItem('backup_model', model)
var file_name = 'backup_'+d.getDate()+'.'+(d.getMonth()+1)+'.'+(d.getYear()-100)+'_'+d.getHours()+'.'+d.getMinutes()
var file_path = folder_path+osfs+file_name+'.bbmodel'

View File

@ -26,6 +26,7 @@ var codec = new Codec('project', {
meta: {
format_version: FORMATV,
creation_time: Math.round(new Date().getTime()/1000),
backup: options.backup ? true : undefined,
model_format: Format.id,
box_uv: Project.box_uv
}
@ -160,10 +161,10 @@ var codec = new Codec('project', {
if (model.textures) {
model.textures.forEach(tex => {
var tex_copy = new Texture(tex, tex.uuid).add(false);
if (tex.source && tex.source.substr(0, 5) == 'data:') {
tex_copy.fromDataURL(tex.source)
} else if (isApp && tex.path && fs.existsSync(tex.path)) {
if (isApp && tex.path && fs.existsSync(tex.path) && !model.meta.backup) {
tex_copy.fromPath(tex.path)
} else if (tex.source && tex.source.substr(0, 5) == 'data:') {
tex_copy.fromDataURL(tex.source)
}
})
}
@ -233,7 +234,7 @@ BARS.defineActions(function() {
category: 'file',
keybind: new Keybind({key: 83, ctrl: true, alt: true}),
click: function () {
saveTextures()
saveTextures(true)
if (isApp && ModelMeta.save_path) {
codec.write(codec.compile(), ModelMeta.save_path);
} else {
@ -247,7 +248,7 @@ BARS.defineActions(function() {
category: 'file',
keybind: new Keybind({key: 83, ctrl: true, alt: true, shift: true}),
click: function () {
saveTextures()
saveTextures(true)
codec.export()
}
})

View File

@ -833,7 +833,7 @@ class Texture {
var image = nativeImage.createFromDataURL(scope.source).toPNG()
}
tex_version++;
if (!as && this.path && this.path.substr(1,1) === ':' && fs.existsSync(this.path)) {
if (!as && this.path && fs.existsSync(this.path)) {
fs.writeFile(this.path, image, function (err) {
scope.fromPath(scope.path)
})
@ -1018,10 +1018,11 @@ class Texture {
new Property(Texture, 'boolean', 'particle')
function saveTextures() {
textures.forEach(function(t) {
if (!t.saved) {
t.save()
function saveTextures(lazy = false) {
textures.forEach(function(tex) {
if (!tex.saved) {
if (lazy && isApp && (!tex.path || !fs.existsSync(tex.path))) return;
tex.save()
}
})
}