Skip to content

Commit d0c1bfe

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Improve Blueprint settings and node configs
1 parent b6d92ce commit d0c1bfe

22 files changed

Lines changed: 1635 additions & 990 deletions
Lines changed: 63 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,75 @@
1-
import { mount } from 'svelte'
2-
import { observable } from 'svelte-observable-store'
3-
import { SvelteDialog } from 'svelte-patching-tools/blockbench'
4-
import { PACKAGE } from '../../constants'
1+
import { SvelteDialogSidebar } from 'svelte-patching-tools/blockbench'
52
import { updateRotationConstraints } from '../../formats/blueprint'
6-
import { type ExportMode } from '../../formats/blueprint/settings'
3+
import {
4+
EXPORT,
5+
EXPORT_DEBUG,
6+
OPEN_ABOUT,
7+
OPEN_DOCUMENTATION,
8+
} from '../../interface/animatedJavaBarItem'
79
import { updateAllCubeOutlines } from '../../mods/cube'
8-
import { SUPPORTED_MINECRAFT_VERSIONS } from '../../systems/global'
9-
import { localize as translate } from '../../util/lang'
10-
import { openBlueprintSettingsv2 } from '../blueprintSettingsv2/blueprintSettings'
11-
import BlueprintSettings from './blueprintSettings.svelte'
12-
import BlueprintSettingsAds from './blueprintSettingsAds.svelte'
10+
import { createScopedTranslator } from '../../util/lang'
11+
import Footer from './footer.svelte'
12+
import Datapack from './pages/datapack.svelte'
13+
import EventFunctions from './pages/eventFunctions.svelte'
14+
import General from './pages/general.svelte'
15+
import Misc from './pages/misc.svelte'
16+
import Resourcepack from './pages/resourcepack.svelte'
1317

14-
function getSettings() {
15-
return {
16-
blueprintName: observable(Project!.name),
17-
textureSizeX: observable(Project!.texture_width),
18-
textureSizeY: observable(Project!.texture_height),
19-
showRenderBox: observable(Project!.animated_java.show_render_box),
20-
autoRenderBox: observable(Project!.animated_java.auto_render_box),
21-
renderBoxX: observable(Project!.animated_java.render_box[0]),
22-
renderBoxY: observable(Project!.animated_java.render_box[1]),
23-
// Export Settings
24-
enablePluginMode: observable(Project!.animated_java.enable_plugin_mode),
25-
exportNamespace: observable(Project!.animated_java.export_namespace),
26-
resourcePackExportMode: observable(
27-
Project!.animated_java.resource_pack_export_mode as string
28-
),
29-
dataPackExportMode: observable(Project!.animated_java.data_pack_export_mode as string),
30-
targetMinecraftVersion: observable(
31-
Project!.animated_java.target_minecraft_version as string
32-
),
33-
// Resource Pack Settings
34-
displayItem: observable(Project!.animated_java.display_item),
35-
customModelDataOffset: observable(Project!.animated_java.custom_model_data_offset),
36-
enableAdvancedResourcePackSettings: observable(
37-
Project!.animated_java.enable_advanced_resource_pack_settings
38-
),
39-
resourcePack: observable(Project!.animated_java.resource_pack),
40-
// Data Pack Settings
41-
enableAdvancedDataPackSettings: observable(
42-
Project!.animated_java.enable_advanced_data_pack_settings
43-
),
44-
dataPack: observable(Project!.animated_java.data_pack),
45-
onSummonFunction: observable(Project!.animated_java.on_summon_function),
46-
onRemoveFunction: observable(Project!.animated_java.on_remove_function),
47-
onPreTickFunction: observable(Project!.animated_java.on_pre_tick_function),
48-
onPostTickFunction: observable(Project!.animated_java.on_post_tick_function),
49-
interpolationDuration: observable(Project!.animated_java.interpolation_duration),
50-
teleportationDuration: observable(Project!.animated_java.teleportation_duration),
51-
autoUpdateRigOrientation: observable(Project!.animated_java.auto_update_rig_orientation),
52-
useStorageForAnimation: observable(Project!.animated_java.use_storage_for_animation),
53-
// Plugin Settings
54-
bakedAnimations: observable(Project!.animated_java.baked_animations),
55-
jsonFile: observable(Project!.animated_java.json_file),
56-
}
57-
}
58-
59-
function setSettings(settings: ReturnType<typeof getSettings>) {
60-
if (!Project) return
61-
Project.name = settings.blueprintName.get()
62-
63-
Project.setResolution(settings.textureSizeX.get(), settings.textureSizeY.get(), true)
18+
const localize = createScopedTranslator('dialog.blueprint_settings')
6419

65-
Project.animated_java.show_render_box = settings.showRenderBox.get()
66-
Project.animated_java.auto_render_box = settings.autoRenderBox.get()
67-
Project.animated_java.render_box = [settings.renderBoxX.get(), settings.renderBoxY.get()]
68-
69-
// Export Settings
70-
Project.animated_java.enable_plugin_mode = settings.enablePluginMode.get()
71-
Project.pluginMode.set(settings.enablePluginMode.get()) // Required to update the project title.
72-
Project.animated_java.export_namespace = settings.exportNamespace.get()
73-
Project.animated_java.resource_pack_export_mode =
74-
settings.resourcePackExportMode.get() as ExportMode
75-
Project.animated_java.data_pack_export_mode = settings.dataPackExportMode.get() as ExportMode
76-
Project.animated_java.target_minecraft_version =
77-
settings.targetMinecraftVersion.get() as SUPPORTED_MINECRAFT_VERSIONS
78-
// Resource Pack Settings
79-
Project.animated_java.display_item = settings.displayItem.get()
80-
Project.animated_java.custom_model_data_offset = settings.customModelDataOffset.get()
81-
Project.animated_java.enable_advanced_resource_pack_settings =
82-
settings.enableAdvancedResourcePackSettings.get()
83-
Project.animated_java.resource_pack = settings.resourcePack.get()
84-
// Data Pack Settings
85-
Project.animated_java.enable_advanced_data_pack_settings =
86-
settings.enableAdvancedDataPackSettings.get()
87-
Project.animated_java.data_pack = settings.dataPack.get()
88-
Project.animated_java.on_summon_function = settings.onSummonFunction.get()
89-
Project.animated_java.on_remove_function = settings.onRemoveFunction.get()
90-
Project.animated_java.on_pre_tick_function = settings.onPreTickFunction.get()
91-
Project.animated_java.on_post_tick_function = settings.onPostTickFunction.get()
92-
Project.animated_java.interpolation_duration = settings.interpolationDuration.get()
93-
Project.animated_java.teleportation_duration = settings.teleportationDuration.get()
94-
Project.animated_java.auto_update_rig_orientation = settings.autoUpdateRigOrientation.get()
95-
Project.animated_java.use_storage_for_animation = settings.useStorageForAnimation.get()
96-
// Plugin Settings
97-
Project.animated_java.baked_animations = settings.bakedAnimations.get()
98-
Project.animated_java.json_file = settings.jsonFile.get()
99-
console.log('Successfully saved project settings', Project)
100-
}
101-
102-
export function openBlueprintSettingsDialog() {
103-
if (!Project) return
104-
105-
return openBlueprintSettingsv2()
106-
107-
const settings = getSettings()
108-
const dialog = new SvelteDialog({
109-
id: `${PACKAGE.name}:blueprintSettingsDialog`,
110-
title: translate('dialog.blueprint_settings.title'),
111-
width: 800,
112-
component: BlueprintSettings,
113-
props: settings,
114-
onOpen() {
115-
mount(BlueprintSettingsAds, { target: dialog.object! })
116-
dialog.object!.style.top = ''
20+
export function openBlueprintSettings() {
21+
const dialog = new SvelteDialogSidebar({
22+
id: `animated_java_blueprint_settings`,
23+
title: 'Blueprint Settings',
24+
pages: {
25+
general: {
26+
component: General,
27+
label: localize('pages.general.title'),
28+
icon: 'settings',
29+
},
30+
datapack: {
31+
component: Datapack,
32+
condition: () => Project.pluginMode.get() === false,
33+
label: localize('pages.datapack.title'),
34+
icon: 'database',
35+
},
36+
resourcepack: {
37+
component: Resourcepack,
38+
condition: () => Project.pluginMode.get() === false,
39+
label: localize('pages.resource_pack.title'),
40+
icon: 'image',
41+
},
42+
eventFunctions: {
43+
component: EventFunctions,
44+
condition: () => Project.pluginMode.get() === false,
45+
label: localize('pages.event_functions.title'),
46+
icon: 'functions',
47+
},
48+
misc: {
49+
component: Misc,
50+
label: localize('pages.misc.title'),
51+
icon: 'tune',
52+
},
53+
},
54+
footer: {
55+
component: Footer,
11756
},
57+
pageSwitchActions: [
58+
OPEN_DOCUMENTATION.get()!,
59+
OPEN_ABOUT.get()!,
60+
EXPORT_DEBUG.get()!,
61+
EXPORT.get()!,
62+
],
63+
width: 1024,
64+
defaultPage: 'general',
11865
disableKeybinds: true,
119-
onConfirm() {
120-
setSettings(settings)
66+
buttons: ['Close'],
67+
onClose: () => {
12168
updateRotationConstraints()
12269
updateAllCubeOutlines()
12370
Canvas.updateAll()
12471
},
12572
})
126-
return dialog.show()
73+
dialog.show()
74+
return dialog
12775
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div><span>*</span> = Required</div>
2+
3+
<style>
4+
div {
5+
flex-grow: 1;
6+
display: flex;
7+
align-items: center;
8+
gap: 4px;
9+
}
10+
span {
11+
color: var(--color-accent);
12+
}
13+
</style>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<script lang="ts">
2+
import { onDestroy } from 'svelte'
3+
import { validateDataPackFolder, validateZipPath } from '../../../formats/blueprint/settings'
4+
import BoxSelect from '../../../svelteComponents/sidebarDialogItems/boxSelect.svelte'
5+
import Checkbox from '../../../svelteComponents/sidebarDialogItems/checkbox.svelte'
6+
import NumberSlider from '../../../svelteComponents/sidebarDialogItems/numberSlider.svelte'
7+
import SelectFile from '../../../svelteComponents/sidebarDialogItems/selectFile.svelte'
8+
import SelectFolder from '../../../svelteComponents/sidebarDialogItems/selectFolder.svelte'
9+
import { createScopedTranslator } from '../../../util/lang'
10+
11+
const translate = createScopedTranslator('dialog.blueprint_settings')
12+
13+
let dataPackExportFormat = $state(Project.animated_java.data_pack_export_mode)
14+
let dataPackLocation = $state(Project.animated_java.data_pack)
15+
let animationSystem = $state(
16+
Project.animated_java.use_storage_for_animation ? 'storage' : 'functions'
17+
)
18+
let interpolationDuration = $state(Project.animated_java.interpolation_duration)
19+
let teleportationDuration = $state(Project.animated_java.teleportation_duration)
20+
let autoUpdateRigOrientation = $state(Project.animated_java.auto_update_rig_orientation)
21+
22+
onDestroy(() => {
23+
Project.animated_java.data_pack_export_mode = dataPackExportFormat
24+
Project.animated_java.data_pack = dataPackLocation
25+
Project.animated_java.use_storage_for_animation = animationSystem === 'storage'
26+
Project.animated_java.interpolation_duration = interpolationDuration
27+
Project.animated_java.teleportation_duration = teleportationDuration
28+
Project.animated_java.auto_update_rig_orientation = autoUpdateRigOrientation
29+
})
30+
</script>
31+
32+
<div class="dialog-page-container">
33+
<BoxSelect
34+
label={translate('data_pack_export_mode.title')}
35+
options={{
36+
folder: {
37+
type: 'text',
38+
label: translate('data_pack_export_mode.options.folder.title'),
39+
description: translate('data_pack_export_mode.options.folder.description'),
40+
},
41+
zip: {
42+
type: 'text',
43+
label: translate('data_pack_export_mode.options.zip.title'),
44+
description: translate('data_pack_export_mode.options.zip.description'),
45+
},
46+
none: {
47+
type: 'text',
48+
label: translate('data_pack_export_mode.options.none.title'),
49+
description: translate('data_pack_export_mode.options.none.description'),
50+
},
51+
}}
52+
bind:selected={dataPackExportFormat}
53+
></BoxSelect>
54+
55+
{#if dataPackExportFormat === 'folder'}
56+
<SelectFolder
57+
label={translate('data_pack.folder.title')}
58+
description={translate('data_pack.folder.description')}
59+
bind:value={dataPackLocation}
60+
checkValue={validateDataPackFolder}
61+
required
62+
></SelectFolder>
63+
{:else if dataPackExportFormat === 'zip'}
64+
<SelectFile
65+
label={translate('data_pack.zip.title')}
66+
description={translate('data_pack.zip.description')}
67+
bind:value={dataPackLocation}
68+
checkValue={validateZipPath}
69+
required
70+
></SelectFile>
71+
{/if}
72+
73+
{#if dataPackExportFormat !== 'none'}
74+
<NumberSlider
75+
label={translate('interpolation_duration.title')}
76+
description={translate('interpolation_duration.description')}
77+
bind:value={interpolationDuration}
78+
step={1}
79+
min={0}
80+
max={2147483647}
81+
/>
82+
83+
<NumberSlider
84+
label={translate('teleportation_duration.title')}
85+
description={translate('teleportation_duration.description')}
86+
bind:value={teleportationDuration}
87+
step={1}
88+
min={0}
89+
max={2147483647}
90+
/>
91+
92+
<Checkbox
93+
label={translate('auto_update_rig_orientation.title')}
94+
description={translate('auto_update_rig_orientation.description')}
95+
bind:value={autoUpdateRigOrientation}
96+
></Checkbox>
97+
98+
<BoxSelect
99+
label={translate('animation_system.title')}
100+
description={translate('animation_system.description')}
101+
options={{
102+
functions: {
103+
type: 'text',
104+
label: translate('animation_system.options.functions.label'),
105+
description: translate('animation_system.options.functions.description'),
106+
},
107+
storage: {
108+
type: 'text',
109+
label: translate('animation_system.options.storage.label'),
110+
description: translate('animation_system.options.storage.description'),
111+
},
112+
}}
113+
bind:selected={animationSystem}
114+
></BoxSelect>
115+
{/if}
116+
</div>
117+
118+
<style>
119+
.dialog-page-container {
120+
overflow-y: auto;
121+
max-height: 75vh;
122+
padding-right: 16px;
123+
padding-left: 2px;
124+
}
125+
</style>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script lang="ts">
2+
import { onDestroy } from 'svelte'
3+
import CodeEdit from '../../../svelteComponents/sidebarDialogItems/codeEdit.svelte'
4+
import { createScopedTranslator } from '../../../util/lang'
5+
6+
const translate = createScopedTranslator('dialog.blueprint_settings')
7+
8+
let onSummonFunction = $state(Project.animated_java.on_summon_function)
9+
let onRemoveFunction = $state(Project.animated_java.on_remove_function)
10+
let onPreTickFunction = $state(Project.animated_java.on_pre_tick_function)
11+
let onPostTickFunction = $state(Project.animated_java.on_post_tick_function)
12+
13+
onDestroy(() => {
14+
Project.animated_java.on_summon_function = onSummonFunction
15+
Project.animated_java.on_remove_function = onRemoveFunction
16+
Project.animated_java.on_pre_tick_function = onPreTickFunction
17+
Project.animated_java.on_post_tick_function = onPostTickFunction
18+
})
19+
</script>
20+
21+
<div class="dialog-page-container">
22+
<CodeEdit
23+
label={translate('on_summon_function.title')}
24+
description={translate('on_summon_function.description')}
25+
syntax="mcfunction"
26+
bind:value={onSummonFunction}
27+
></CodeEdit>
28+
29+
<CodeEdit
30+
label={translate('on_remove_function.title')}
31+
description={translate('on_remove_function.description')}
32+
syntax="mcfunction"
33+
bind:value={onRemoveFunction}
34+
></CodeEdit>
35+
36+
<CodeEdit
37+
label={translate('on_pre_tick_function.title')}
38+
description={translate('on_pre_tick_function.description')}
39+
syntax="mcfunction"
40+
bind:value={onPreTickFunction}
41+
></CodeEdit>
42+
43+
<CodeEdit
44+
label={translate('on_post_tick_function.title')}
45+
description={translate('on_post_tick_function.description')}
46+
syntax="mcfunction"
47+
bind:value={onPostTickFunction}
48+
></CodeEdit>
49+
</div>
50+
51+
<style>
52+
.dialog-page-container {
53+
overflow-y: auto;
54+
max-height: 75vh;
55+
padding-right: 16px;
56+
padding-left: 2px;
57+
}
58+
</style>

0 commit comments

Comments
 (0)