function t(str) {
return Editor.T('enhance-kit.' + str);
}
Editor.Panel.extend({
style: `
:host { margin: 5px; }
h1 { margin-left: 15px; }
.desc { color: gray; margin-left: 15px; margin-right: 15px; }
.subdesc { color: gray; }
.sub { margin-left: 30px; margin-right: 30px; }
.hidden { display: none; }
`,
template: `
${t('thread_title')}
${t('thread_desc')}
`,
$: {
unripe_area: '#unripe',
unripe_tip: '#unripe_tip',
ready_area: '#ready',
thread_debug: '#td',
thread_debug_checkbox: '#tdc',
thread_asset_pipeline: '#tap',
thread_asset_pipeline_checkbox: '#tapc',
thread_audio_system: '#fs',
thread_audio_system_checkbox: '#fsc',
thread_audio_system_interval: '#fsi',
thread_audio_system_interval_input: '#fsii',
thread_scheduler: '#ts',
thread_scheduler_checkbox: '#tsc',
},
ready() {
Editor.Ipc.sendToMain('enhance-kit:getSettings', (error, data) => {
if (error) {
this.$unripe_tip.textContent = 'Error:' + String(error);
this.$unripe_tip.style.color = 'red';
return;
}
if (data.code === 0) {
this.$unripe_area.classList.add('hidden');
this.$ready_area.classList.remove('hidden');
this.$thread_debug_checkbox.checked = data.CC_WORKER_DEBUG;
this.$thread_asset_pipeline_checkbox.checked = data.CC_WORKER_ASSET_PIPELINE;
this.$thread_audio_system_checkbox.checked = data.CC_WORKER_AUDIO_SYSTEM;
this.$thread_audio_system_interval_input.value = data.CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL;
this.$thread_scheduler_checkbox.checked = data.CC_WORKER_SCHEDULER;
this.$thread_debug_checkbox.addEventListener('change', () => {
this.setSettings("CC_WORKER_DEBUG", this.$thread_debug_checkbox.checked);
});
this.$thread_asset_pipeline_checkbox.addEventListener('change', () => {
this.setSettings("CC_WORKER_ASSET_PIPELINE", this.$thread_asset_pipeline_checkbox.checked);
});
const onAudioSystemEnableChange = (enabled) => {
this.$thread_audio_system_interval_input.disabled = !enabled;
};
onAudioSystemEnableChange(this.$thread_asset_pipeline_checkbox.checked);
this.$thread_audio_system_checkbox.addEventListener('change', () => {
const enabled = this.$thread_audio_system_checkbox.checked;
onAudioSystemEnableChange(enabled);
this.setSettings("CC_WORKER_AUDIO_SYSTEM", enabled);
});
this.$thread_audio_system_interval_input.addEventListener('confirm', () => {
this.setSettings("CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL", this.$thread_audio_system_interval_input.value);
});
this.$thread_scheduler_checkbox.addEventListener('change', () => {
this.setSettings("CC_WORKER_SCHEDULER", this.$thread_scheduler_checkbox.checked);
});
} else {
this.$unripe_tip.textContent = data.errMsg;
this.$unripe_tip.style.color = 'red';
}
}, 5000);
},
async setSettings(macro, value) {
return new Promise((resolve, reject) => {
Editor.Ipc.sendToMain('enhance-kit:setSettings', macro, value, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
}, 3000);
});
},
});