Keep file name when importing skin

Fix issue with undoing texture edits in web app
This commit is contained in:
JannisX11 2023-07-15 22:01:29 +02:00
parent 0526b35d09
commit 86b4bb720e
3 changed files with 17 additions and 7 deletions

View File

@ -319,6 +319,7 @@ function buildForm(dialog) {
function fileCB(files) { function fileCB(files) {
data.value = files[0].path; data.value = files[0].path;
data.content = files[0].content; data.content = files[0].content;
data.file = files[0];
input.val(settings.streamer_mode.value ? `[${tl('generic.redacted')}]` : data.value); input.val(settings.streamer_mode.value ? `[${tl('generic.redacted')}]` : data.value);
dialog.updateFormValues() dialog.updateFormValues()
} }
@ -345,7 +346,11 @@ function buildForm(dialog) {
type: data.filetype, type: data.filetype,
startpath: data.value, startpath: data.value,
custom_writer: () => {}, custom_writer: () => {},
}, fileCB); }, path => {
data.value = path;
input.val(settings.streamer_mode.value ? `[${tl('generic.redacted')}]` : data.value);
dialog.updateFormValues()
});
break; break;
} }
}) })
@ -662,7 +667,11 @@ window.Dialog = class Dialog {
result[form_id] = data.bar.find('input#'+form_id).is(':checked') result[form_id] = data.bar.find('input#'+form_id).is(':checked')
break; break;
case 'file': case 'file':
result[form_id] = isApp ? data.value : data.content; if (data.return_as == 'file') {
result[form_id] = data.file;
} else {
result[form_id] = isApp ? data.value : data.content;
}
break; break;
} }
} }

View File

@ -60,7 +60,7 @@ const codec = new Codec('skin_model', {
this.dispatchEvent('compile', {model: entitymodel, options}); this.dispatchEvent('compile', {model: entitymodel, options});
return entitymodel return entitymodel
}, },
parse(data, resolution, texture_path, pose = true, layer_template) { parse(data, resolution, texture_file, pose = true, layer_template) {
this.dispatchEvent('parse', {model: data}); this.dispatchEvent('parse', {model: data});
Project.texture_width = data.texturewidth || 64; Project.texture_width = data.texturewidth || 64;
Project.texture_height = data.textureheight || 64; Project.texture_height = data.textureheight || 64;
@ -124,8 +124,8 @@ const codec = new Codec('skin_model', {
if (!Cube.all.find(cube => cube.box_uv)) { if (!Cube.all.find(cube => cube.box_uv)) {
Project.box_uv = false; Project.box_uv = false;
} }
if (texture_path) { if (texture_file) {
var texture = new Texture().fromPath(texture_path).add(false); var texture = new Texture().fromFile(texture_file).add(false);
} else if (resolution) { } else if (resolution) {
var texture = generateTemplate( var texture = generateTemplate(
Project.texture_width*resolution, Project.texture_width*resolution,
@ -282,6 +282,7 @@ const skin_dialog = new Dialog({
extensions: ['png'], extensions: ['png'],
readtype: 'image', readtype: 'image',
filetype: 'PNG', filetype: 'PNG',
return_as: 'file'
}, },
pose: {type: 'checkbox', label: 'dialog.skin.pose', value: true, condition: form => (!!skin_presets[form.model].pose)}, pose: {type: 'checkbox', label: 'dialog.skin.pose', value: true, condition: form => (!!skin_presets[form.model].pose)},
layer_template: {type: 'checkbox', label: 'dialog.skin.layer_template', value: false} layer_template: {type: 'checkbox', label: 'dialog.skin.layer_template', value: false}
@ -290,7 +291,7 @@ const skin_dialog = new Dialog({
onConfirm(result) { onConfirm(result) {
if (result.model == 'flat_texture') { if (result.model == 'flat_texture') {
if (result.texture) { if (result.texture) {
Codecs.image.load(dataUrl); Codecs.image.load(result.texture);
} else { } else {
Formats.image.new(); Formats.image.new();
} }

View File

@ -316,7 +316,7 @@ class Texture {
Merge.string(this, data, 'mode', mode => (mode === 'bitmap' || mode === 'link')) Merge.string(this, data, 'mode', mode => (mode === 'bitmap' || mode === 'link'))
Merge.boolean(this, data, 'saved') Merge.boolean(this, data, 'saved')
Merge.boolean(this, data, 'keep_size') Merge.boolean(this, data, 'keep_size')
if (this.mode === 'bitmap') { if (this.mode === 'bitmap' || !isApp) {
Merge.string(this, data, 'source') Merge.string(this, data, 'source')
} else if (data.path) { } else if (data.path) {
this.source = this.path.replace(/#/g, '%23') + '?' + tex_version; this.source = this.path.replace(/#/g, '%23') + '?' + tex_version;