Skip to content

Commit

Permalink
Refactored logging system + Misc (not much)
Browse files Browse the repository at this point in the history
Misc:
- Added `onMount`, `beforeUpdate` and `afterUpdate` in all components where those were missing / might be needed (in most cases `beforeUpdate` and `afterUpdate`).
- Minor Code refactorings / comment additions / changes etc.
  • Loading branch information
0x088730 committed Dec 10, 2021
1 parent 8f8a714 commit c26cd16
Show file tree
Hide file tree
Showing 47 changed files with 1,864 additions and 860 deletions.
38 changes: 25 additions & 13 deletions src/ani/SvelthreeAnimationManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Object3D, Scene } from "three"
import SvelthreeAnimationProp from "./SvelthreeAnimationProp"
import { verbose_mode } from "../utils/SvelthreeLogger"

// TODO TOFIX This seems to be a MESS, DEBUG! (switching Scenes)
export default class SvelthreeAnimationManager {
Expand All @@ -17,24 +18,34 @@ export default class SvelthreeAnimationManager {

handleCurrentSceneStatus(currentSceneActive: boolean) {
if (currentSceneActive) {
console.warn(
"SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : currentSceneActive = true!"
)
if (verbose_mode()) {
console.debug(
"SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : currentSceneActive = true!"
)
}
if (this.aniauto) {
console.warn("SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : this.aniauto = true!")
if (verbose_mode()) {
console.debug(
"SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : this.aniauto = true!"
)
}
this.handleSceneActive()
}
} else {
console.warn(
"SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : currentSceneActive = false!"
)
if (verbose_mode()) {
console.debug(
"SVELTHREE > SvelthreeAnimationManager > handleCurrentSceneStatus : currentSceneActive = false!"
)
}
this.handleSceneInActive()
}
}

//active / reactivated
handleSceneActive() {
console.warn("SVELTHREE > SvelthreeAnimationManager > handleSceneActive!")
if (verbose_mode()) {
console.debug("SVELTHREE > SvelthreeAnimationManager > handleSceneActive!")
}
//check if animation has been initiated, if so try to execute 'onSceneReactivated'...
if (this.animationInitiated() === true) {
this.tryOnSceneReactivated()
Expand All @@ -45,18 +56,19 @@ export default class SvelthreeAnimationManager {
}

initiateAnimation(): void {
//console.info("SVELTHREE > SvelthreeAnimationManager > initiateAnimation!")
//if (verbose_mode()) console.debug("SVELTHREE > SvelthreeAnimationManager > initiateAnimation!")
//if animation is a function it has not been initiated / started yet (otherwise object)
!this.scene.userData.isActive
? console.warn(
"SVELTHREE > SvelthreeAnimationManager : initiateAnimation : You're about to initiate an animation in an inactive Scene!"
)
: null
this.animation = this.animation.initiate(this.obj, ...arguments)
console.info(
"SVELTHREE > SvelthreeAnimationManager > initiateAnimation : after initialization: this.animation:",
this.animation
)
if (verbose_mode())
console.debug(
"SVELTHREE > SvelthreeAnimationManager > initiateAnimation : after initialization: this.animation:",
this.animation
)
try {
this.animation.onStart()
} catch (error) {
Expand Down
92 changes: 50 additions & 42 deletions src/components-internal/Camera.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ This is an internal **svelthree** _Camera_ Component.
import { svelthreeStores } from "../stores"
import { CameraUtils, PropUtils, SvelthreeProps } from "../utils"
import SvelthreeAnimation from "./SvelthreeAnimation.svelte"
import { get_current_component } from "svelte/internal"
import { c_rs_int, c_dev, c_lc_int, c_mau, verbose_mode, get_comp_name_int } from "../utils/SvelthreeLogger"
import type { LogLC, LogDEV } from "../utils/SvelthreeLogger"
const css_rs = "color: red;font-weight:bold;"
const css_ba = "color: blue;font-weight:bold;"
const css_aa = "color: green;font-weight:bold;"
export let logInfo: boolean = false
export let logRS: boolean = false
export let logLC: boolean = false
const c_name = get_comp_name_int(get_current_component())
const verbose: boolean = verbose_mode()
export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = undefined
export let log_rs: boolean = false
export let log_lc: { [P in keyof LogLC]: LogLC[P] } = undefined
export let log_mau: boolean = false
// #endregion
Expand All @@ -57,17 +61,22 @@ This is an internal **svelthree** _Camera_ Component.
scene.add(cam)
if (logInfo)
console.info("SVELTHREE > Camera : " + cam.type + " was added to scene!", {
cam: cam,
scene: scene,
total: scene.children.length
})
if (verbose && log_dev) {
console.debug(
...c_dev(c_name, `${cam.type} was added to scene!`, {
cam: cam,
scene: scene,
total: scene.children.length
})
)
}
cam.userData.id = id
cam.userData.isActive = false
cam.userData.indexInCameras = $svelthreeStores[sti].cameras.length
debugger
$svelthreeStores[sti].cameras.push({
camera: cam,
id: id,
Expand Down Expand Up @@ -117,7 +126,7 @@ This is an internal **svelthree** _Camera_ Component.
$: props && sProps ? updateProps() : null
function updateProps() {
if (logRS) console.log("%c*--------> Camera > reactive statement! props", `${css_rs}`, props)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "props", props))
sProps.update(props)
}
Expand Down Expand Up @@ -149,7 +158,7 @@ This is an internal **svelthree** _Camera_ Component.
// TODO check one more time with orbit controls on
afterUpdate(() => {
console.info("SVELTHREE > Camera : afterUpdate!")
if (verbose && log_lc && (log_lc.all || log_lc.au)) console.info(...c_lc_int(c_name, "afterUpdate"))
tryOrbitControlsUpdate()
})
Expand All @@ -168,48 +177,47 @@ This is an internal **svelthree** _Camera_ Component.
//#region --- 'Object3D' Specific Code
const w_sh = PropUtils.getShortHandAttrWarnings(`SVELTHREE > ${cam.type} >`)
const wrn = PropUtils.warn
//$: !matrix && cam && pos ? PropUtils.setPositionFromValue(cam, pos) : pos && cam ? wrn(w_sh.pos) : null
$: !matrix && cam && pos ? setPositionFromValue() : pos && cam ? wrn(w_sh.pos) : null
//$: !matrix && cam && pos ? PropUtils.setPositionFromValue(cam, pos) : pos && cam ? console.warn(w_sh.pos) : null
$: !matrix && cam && pos ? setPositionFromValue() : pos && cam ? console.warn(w_sh.pos) : null
function setPositionFromValue() {
if (logRS) console.log("%c*--------> Camera > reactive statement! pos", `${css_rs}`, pos)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "pos", pos))
PropUtils.setPositionFromValue(cam, pos)
}
//$: !matrix && !quat && cam && rot ? PropUtils.setRotationFromValue(cam, rot) : rot && cam ? wrn(w_sh.rot) : null
$: !matrix && !quat && cam && rot ? setRotationFromValue() : rot && cam ? wrn(w_sh.rot) : null
//$: !matrix && !quat && cam && rot ? PropUtils.setRotationFromValue(cam, rot) : rot && cam ? console.warn(w_sh.rot) : null
$: !matrix && !quat && cam && rot ? setRotationFromValue() : rot && cam ? console.warn(w_sh.rot) : null
function setRotationFromValue() {
if (logRS) console.log("%c*--------> Camera > reactive statement! rot", `${css_rs}`, rot)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "rot", rot))
PropUtils.setRotationFromValue(cam, rot)
}
//$: !matrix && cam && quat ? PropUtils.setQuaternionFromValue(cam, quat) : quat && cam ? wrn(w_sh.quat) : null
$: !matrix && cam && quat ? setQuaternionFromValue() : quat && cam ? wrn(w_sh.quat) : null
//$: !matrix && cam && quat ? PropUtils.setQuaternionFromValue(cam, quat) : quat && cam ? console.warn(w_sh.quat) : null
$: !matrix && cam && quat ? setQuaternionFromValue() : quat && cam ? console.warn(w_sh.quat) : null
function setQuaternionFromValue() {
if (logRS) console.log("%c*--------> Camera > reactive statement! quat", `${css_rs}`, quat)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "quat", quat))
PropUtils.setQuaternionFromValue(cam, quat)
}
// RECONSIDER TODO currently not using 'scale' in cameras
//$: !matrix && cam && scale ? PropUtils.setScaleFromValue(cam, scale) : scale && cam ? wrn(w_sh.scale) : null
//$: !matrix && cam && scale ? PropUtils.setScaleFromValue(cam, scale) : scale && cam ? console.warn(w_sh.scale) : null
//$: !matrix && cam && lookAt ? PropUtils.setLookAtFromValue(cam, lookAt) : lookAt && cam ? wrn(w_sh.lookAt) : null
$: !matrix && cam && lookAt ? setLookAtFromValue() : lookAt && cam ? wrn(w_sh.lookAt) : null
//$: !matrix && cam && lookAt ? PropUtils.setLookAtFromValue(cam, lookAt) : lookAt && cam ? console.warn(w_sh.lookAt) : null
$: !matrix && cam && lookAt ? setLookAtFromValue() : lookAt && cam ? console.warn(w_sh.lookAt) : null
function setLookAtFromValue() {
if (logRS) console.log("%c*--------> Camera > reactive statement! lookAt", `${css_rs}`, lookAt)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "lookAt", lookAt))
PropUtils.setLookAtFromValue(cam, lookAt)
}
//$: matrix && cam ? PropUtils.setMatrixFromValue(cam, matrix) : null
$: matrix && cam ? setMatrixFromValue() : null
function setMatrixFromValue() {
if (logRS) console.log("%c*--------> Camera > reactive statement! matrix", `${css_rs}`, matrix)
if (verbose && log_rs) console.debug(...c_rs_int(c_name, "matrix", matrix))
PropUtils.setMatrixFromValue(cam, matrix)
}
Expand Down Expand Up @@ -307,32 +315,32 @@ This is an internal **svelthree** _Camera_ Component.
fnOnMount
? () => fnOnMount(self)
: () => {
if (logLC) logCurrentState(`*----> Camera > onMount`, null)
if (logInfo) console.info("SVELTHREE > onMount : Camera")
console.warn("SVELTHREE > onMount : Camera : cam.matrixAutoUpdate", cam.matrixAutoUpdate)
if (verbose && log_lc && (log_lc.all || log_lc.om)) console.info(...c_lc_int(c_name, "onMount"))
if (verbose && log_mau) {
console.debug(...c_mau(c_name, "onMount : cam.matrixAutoUpdate", cam.matrixAutoUpdate))
}
return () => {
if (logInfo) console.info("SVELTHREE > onDestroy : Camera")
if (verbose && log_lc) console.info(...c_lc_int(c_name, "onDestroy"))
removeCameraFromParent()
}
}
)
beforeUpdate(() => {
if (verbose && log_lc && (log_lc.all || log_lc.bu)) console.info(...c_lc_int(c_name, "beforeUpdate"))
})
afterUpdate(() => {
if (logLC) logCurrentState("%c*------> Camera > afterUpdate", css_aa)
if (verbose && log_lc && (log_lc.all || log_lc.om)) console.info(...c_lc_int(c_name, "afterUpdate"))
if (cam.matrixWorldNeedsUpdate === false) {
cam.matrixAutoUpdate = mau
}
if (verbose && log_lc && (log_lc.all || log_lc.od)) {
console.debug(...c_mau(c_name, "afterUpdate : cam.matrixAutoUpdate", cam.matrixAutoUpdate))
}
})
beforeUpdate(() => {
if (logLC) logCurrentState("%c*------> Camera > beforeUpdate", css_ba)
})
function logCurrentState(prefix: string, css: string) {
console.log(`${prefix}!`, `${css}`)
}
// #endregion
</script>

Expand Down
Loading

0 comments on commit c26cd16

Please sign in to comment.