Skip to content

Commit 53c80fd

Browse files
committed
breaking stuff is my favorite
- Fixed #30 - Merged #44
1 parent d4665d0 commit 53c80fd

File tree

8 files changed

+104
-42
lines changed

8 files changed

+104
-42
lines changed

src/animatedJava.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const ANIMATED_JAVA = {
6363
format: modelFormat,
6464
registerSettingRenderer,
6565
get variants() {
66-
return store.get('variants')
66+
return store.get('states')
6767
},
6868
logging: false, //enable logging in production
6969
PromiseWrapper<T>(promise: Promise<T>): Promise<T> {

src/exporters/animationExporter.ts

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ interface animationExporterSettings {
3232
rootTag: string
3333
rootEntityNbt: string
3434
mcbConfigPath: string
35+
autoDistance: number
36+
autoDistanceMovementThreshold: number
37+
manualDistance: number
3538
}
3639

3740
interface MCBConfig {
@@ -94,16 +97,27 @@ async function createMCFile(
9497

9598
const staticAnimationUuid = store.get('static_animation_uuid')
9699
const staticFrame = animations[staticAnimationUuid].frames[0].bones
97-
const staticDistance = roundToN(
98-
animations[staticAnimationUuid].maxDistance + -headYOffset,
99-
1000
100-
)
101-
const maxDistance = roundToN(
102-
Object.values(animations).reduce((o, n) => {
103-
return Math.max(o, n.maxDistance)
104-
}, -Infinity) + -headYOffset,
105-
1000
106-
)
100+
// let staticDistance = 10
101+
let maxDistance = 10
102+
if (exporterSettings.autoDistance) {
103+
// staticDistance = roundToN(
104+
// animations[staticAnimationUuid].maxDistance + -headYOffset,
105+
// 1000
106+
// )
107+
108+
maxDistance = roundToN(
109+
Object.values(animations).reduce((o, n) => {
110+
return Math.max(o, n.maxDistance)
111+
}, -Infinity) +
112+
exporterSettings.autoDistanceMovementThreshold +
113+
-headYOffset,
114+
1000
115+
)
116+
} else {
117+
// staticDistance = exporterSettings.manualDistance
118+
maxDistance = exporterSettings.manualDistance
119+
}
120+
107121
animations = removeKeyGently(staticAnimationUuid, animations)
108122
console.log(animations)
109123

@@ -224,7 +238,7 @@ async function createMCFile(
224238
function this {
225239
execute (if entity @s[tag=${tags.root}] at @s) {
226240
scoreboard players operation # ${scoreboards.id} = @s ${scoreboards.id}
227-
execute as @e[type=${entityTypes.bone},tag=${tags.model},distance=..${staticDistance}] if score @s ${scoreboards.id} = # ${scoreboards.id} run kill @s
241+
execute as @e[type=${entityTypes.bone},tag=${tags.model},distance=..${maxDistance}] if score @s ${scoreboards.id} = # ${scoreboards.id} run kill @s
228242
kill @s
229243
} else {
230244
tellraw @s ${rootExeErrorJsonText.replace('%functionName', `${projectName}:remove/all`)}
@@ -391,7 +405,7 @@ async function createMCFile(
391405
# Summon all bone entities
392406
${summons.map(v => v.toString()).join('\n')}
393407
# Update rotation and ID of bone entities to match the root entity
394-
execute as @e[type=${entityTypes.bone},tag=${tags.model},tag=new,distance=..${staticDistance}] positioned as @s run {
408+
execute as @e[type=${entityTypes.bone},tag=${tags.model},tag=new,distance=..${maxDistance}] positioned as @s run {
395409
scoreboard players operation @s ${scoreboards.id} = .aj.last_id ${scoreboards.internal}
396410
tp @s ~ ~ ~ ~ ~
397411
tag @s remove new
@@ -543,10 +557,9 @@ async function createMCFile(
543557
title: tl(
544558
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.title'
545559
),
546-
lines:
547-
tl(
548-
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.body'
549-
)
560+
lines: tl(
561+
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.body'
562+
)
550563
.split('\n')
551564
.map((line: string) => `<p>${line}</p>`),
552565
},
@@ -1045,6 +1058,56 @@ const Exporter = (AJ: any) => {
10451058
return typeof value === 'boolean'
10461059
},
10471060
},
1061+
autoDistance: {
1062+
type: 'checkbox',
1063+
default: true,
1064+
populate() {
1065+
return true
1066+
},
1067+
isValid(value: any) {
1068+
return typeof value === 'boolean'
1069+
},
1070+
},
1071+
autoDistanceMovementThreshold: {
1072+
type: 'number',
1073+
default: 1,
1074+
populate() {
1075+
return 1
1076+
},
1077+
isValid(value: any) {
1078+
return !isNaN(value) && value >= 0
1079+
},
1080+
onUpdate(value: any) {
1081+
return Number(value)
1082+
},
1083+
isVisible(settings: any) {
1084+
return settings.animatedJava_exporter_animationExporter
1085+
.autoDistance
1086+
},
1087+
dependencies: [
1088+
'animatedJava_exporter_animationExporter.autoDistance',
1089+
],
1090+
},
1091+
manualDistance: {
1092+
type: 'number',
1093+
default: 10,
1094+
populate() {
1095+
return 10
1096+
},
1097+
isValid(value: any) {
1098+
return !isNaN(value) && value >= 0
1099+
},
1100+
onUpdate(value: any) {
1101+
return Number(value)
1102+
},
1103+
isVisible(settings: any) {
1104+
return !settings.animatedJava_exporter_animationExporter
1105+
.autoDistance
1106+
},
1107+
dependencies: [
1108+
'animatedJava_exporter_animationExporter.autoDistance',
1109+
],
1110+
},
10481111
modelTag: {
10491112
type: 'text',
10501113
default: 'aj.%projectName',

src/lang/en.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ animatedJava.popup.error.unsavedTexture.body: |-
9191
animatedJava.popup.warning.rigFolderUnused.title: Unused rig folder
9292
animatedJava.popup.warning.rigFolderUnused.body: |-
9393
This folder does not contain any existing rigs.
94-
Are you sure you want to use this folder?
94+
Are you sure you want to overwrite this folder?
9595
9696
animatedJava.popup.error.rigFolderAlreadyUsedByOther.title: Chosen rig folder already in use
9797
animatedJava.popup.error.rigFolderAlreadyUsedByOther.body: |-
@@ -138,6 +138,7 @@ animatedJava.setting.predicateFilePath.description: The item model file of the r
138138

139139
animatedJava.setting.transparentTexturePath.name: Transparent Texture Path
140140
animatedJava.setting.transparentTexturePath.description: A transparent texture for adding transparency to variants. Only needed if you're using transparency in your variants.
141+
animatedJava.setting.transparentTexturePath.error.invalidPath: Transparent texture path must be defined if your are using the transparency feature of variants
141142

142143
animatedJava.setting.useCache.name: Use Animation Cache
143144
animatedJava.setting.useCache.description: Only re-render changed animations
@@ -239,6 +240,20 @@ animatedJava_exporter_animationExporter.setting.rootEntityNbt.description: The N
239240
animatedJava_exporter_animationExporter.setting.markerArmorStands.name: Marker Armor Stands
240241
animatedJava_exporter_animationExporter.setting.markerArmorStands.description: When enabled all armor_stands used to display the rig will have no hitbox or collision.
241242

243+
animatedJava_exporter_animationExporter.setting.autoDistance.name: Auto Distance
244+
animatedJava_exporter_animationExporter.setting.autoDistance.description: |-
245+
Automatically calculate the maximum distance required to animate all bones in the rig based on the rendered animations.
246+
247+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.name: Auto Distance Movement Threshold
248+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.description: |-
249+
How much distance to add to the calculated animation distance.
250+
The more distance you add the farther you can move the rig in a single tick without dropping bones
251+
252+
animatedJava_exporter_animationExporter.setting.manualDistance.name: Manual Animation Distance
253+
animatedJava_exporter_animationExporter.setting.manualDistance.description: |-
254+
How far away a bone can be from the root entity before it stops animating.
255+
This setting is intended for advanced users.
256+
242257
animatedJava_exporter_animationExporter.setting.modelTag.name: Model Tag
243258
animatedJava_exporter_animationExporter.setting.modelTag.description: The tag used to select the model
244259

src/modelFormat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const format = new ModelFormat({
309309
uv_rotation: true,
310310
centered_grid: true,
311311
animation_files: true,
312+
animated_textures: true,
312313
icon: 'fa-cube',
313314
codec,
314315
onDeactivation() {

src/settings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const DefaultSettings = {
172172
},
173173
}
174174

175-
function evaluateSetting(namespace, name, value) {
175+
function evaluateSetting(event, namespace, name, value) {
176176
const setting = DefaultSettings[namespace]?.[name]
177177
if (setting) {
178178
if (setting.isValid) {
@@ -240,13 +240,15 @@ class Settings {
240240
Object.defineProperty(value, settings[i], {
241241
get: () => {
242242
return evaluateSetting(
243+
'get',
243244
namespace,
244245
settings[i],
245246
this.get(namespace + '.' + settings[i])
246247
)
247248
},
248249
set: (value) => {
249250
const validatedValue = evaluateSetting(
251+
'set',
250252
namespace,
251253
settings[i],
252254
value
@@ -294,6 +296,7 @@ class Settings {
294296
? DefaultSettings[namespace][name]
295297
.default
296298
: evaluateSetting(
299+
'update',
297300
namespace,
298301
name,
299302
settings[namespace][name]
@@ -410,6 +413,7 @@ class Settings {
410413
get() {
411414
if (_cached2 != UNASSIGNED) return _cached2
412415
_cached2 = evaluateSetting(
416+
'get',
413417
key,
414418
key2,
415419
value2

src/ui/dialogs/settings.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,6 @@ const RenderTemplates = {
128128
</>
129129
)
130130
},
131-
// textarea({ value, setValue, namespace, name, children }) {
132-
// return (
133-
// <>
134-
// <div>{children}</div>
135-
// <div style={{ display: 'inline-block' }}>
136-
// <textarea
137-
// id={`aj.setting.${namespace}.${name}`}
138-
// value={value || ''}
139-
// onChange={(e) => {
140-
// setValue(e.target.value)
141-
// }}
142-
// onBlur={(e) => {
143-
// settings[namespace][name] = e.target.value
144-
// }}
145-
// className="dark_bordered"
146-
// style={{ width: '389%' }}
147-
// />
148-
// </div>
149-
// </>
150-
// )
151-
// },
152131
select({ value, setValue, namespace, name, children, definition }) {
153132
return (
154133
<>

src/util/eventSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EventSystem {
6060
}
6161
dispatch(type: string, payload: any) {
6262
const eventFrame = this.createNewEventFrame()
63-
console.log(`[event (${this.id}): dispatch] `, type)
63+
// console.log(`[event (${this.id}): dispatch] `, type)
6464
Object.freeze(payload)
6565
const recipients = this._getEventListForType(type)
6666
const errors = []

src/util/minecraft/resourcepack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tl } from '../intl'
55
import { format } from '../replace'
66

77
export function getTexturePath(texture: any) {
8-
if (!texture.path) {
8+
if (!texture.path || !texture.saved) {
99
throw new CustomError('Unsaved texture', {
1010
dialog: {
1111
title: tl('animatedJava.popup.error.unsavedTexture.title'),

0 commit comments

Comments
 (0)