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

View File

@ -60,7 +60,7 @@ const codec = new Codec('skin_model', {
this.dispatchEvent('compile', {model: entitymodel, options});
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});
Project.texture_width = data.texturewidth || 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)) {
Project.box_uv = false;
}
if (texture_path) {
var texture = new Texture().fromPath(texture_path).add(false);
if (texture_file) {
var texture = new Texture().fromFile(texture_file).add(false);
} else if (resolution) {
var texture = generateTemplate(
Project.texture_width*resolution,
@ -282,6 +282,7 @@ const skin_dialog = new Dialog({
extensions: ['png'],
readtype: 'image',
filetype: 'PNG',
return_as: 'file'
},
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}
@ -290,7 +291,7 @@ const skin_dialog = new Dialog({
onConfirm(result) {
if (result.model == 'flat_texture') {
if (result.texture) {
Codecs.image.load(dataUrl);
Codecs.image.load(result.texture);
} else {
Formats.image.new();
}

View File

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