-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format, clean up comments, refactor world injection
- Loading branch information
Showing
6 changed files
with
142 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,67 @@ | ||
import { defineComponent, setComponent, useEntityContext } from '@etherealengine/ecs' | ||
|
||
import { defineComponent, useEntityContext, setComponent } from "@etherealengine/ecs" | ||
import { Color, Mesh, MeshStandardMaterial, SphereGeometry } from 'three' | ||
import matches from 'ts-matches' | ||
|
||
import { Mesh, SphereGeometry, MeshStandardMaterial, Color } from "three" | ||
import matches from "ts-matches" | ||
|
||
import React, { useEffect } from "react" | ||
import { VisibleComponent } from "@etherealengine/spatial/src/renderer/components/VisibleComponent" | ||
import { NameComponent } from "@etherealengine/spatial/src/common/NameComponent" | ||
import { addObjectToGroup } from "@etherealengine/spatial/src/renderer/components/GroupComponent" | ||
import { TransformComponent } from "@etherealengine/spatial/src/transform/components/TransformComponent" | ||
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent' | ||
import { addObjectToGroup } from '@etherealengine/spatial/src/renderer/components/GroupComponent' | ||
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent' | ||
import { TransformComponent } from '@etherealengine/spatial/src/transform/components/TransformComponent' | ||
import { useEffect } from 'react' | ||
|
||
export const BubbleComponent = defineComponent({ | ||
//name: The human-readable label for the component. This will be displayed in the editor and debugging tools. | ||
name: "Bubble Component", | ||
/** name: The human-readable label for the component. This will be displayed in the editor and debugging tools. */ | ||
name: 'Bubble Component', | ||
|
||
//onInit: Initializer function that is called when the component is added to an entity. The return type of this function defines the | ||
// schema of the component's runtime data. | ||
/** | ||
* onInit: Initializer function that is called when the component is added to an entity. | ||
* The return type of this function defines the schema of the component's runtime data. | ||
*/ | ||
onInit: (entity) => { | ||
return { | ||
age: 0 as number | ||
} | ||
}, | ||
//onSet: Set function that is called whenever the component's data is updated via the setComponent function. This is where deserialize logic should | ||
// be applied. | ||
|
||
/** | ||
* onSet: Set function that is called whenever setComponent is called. | ||
* This is where deserialize logic should be applied. | ||
*/ | ||
onSet: (entity, component, json) => { | ||
if (!json) return | ||
matches.number.test(json.age) && component.age.set(json.age) | ||
}, | ||
//toJSON: Serializer function that is called when the component is being saved to a scene file or snapshot. This is where serialize logic should | ||
// be applied to convert the component's runtime data into a JSON object. | ||
|
||
/** | ||
* toJSON: Serializer function that is called when the component is being saved to a scene file or snapshot. | ||
* This is where serialize logic should be applied to convert the component's runtime data into a JSON object. | ||
*/ | ||
toJSON: (entity, component) => { | ||
return { | ||
age: component.age.value | ||
} | ||
}, | ||
//reactor: The reactor function is where async reactive logic is defined. Any side-effects that depend upon component data should be defined here. | ||
/** | ||
* reactor: The reactor function is where async reactive logic is defined. Any side-effects that depend upon component data should be defined here. | ||
*/ | ||
reactor: () => { | ||
//get the entity using useEntityContext | ||
/** Get the entity for this component instance */ | ||
const entity = useEntityContext() | ||
|
||
//a useEffect with no dependencies will only run once, when the component is first initialized | ||
/** A useEffect with no dependencies will only run once, when the component is first initialized */ | ||
useEffect(() => { | ||
setComponent(entity, VisibleComponent) // Set if the entity is visible | ||
setComponent(entity, NameComponent, "Bubble") // Give the entity a name | ||
setComponent(entity, TransformComponent) // Give the entity a local transform | ||
/** Set if the entity is visible */ | ||
setComponent(entity, VisibleComponent) | ||
/** Set the name of the entity */ | ||
setComponent(entity, NameComponent, 'Bubble') | ||
/** Give the entity a local transform */ | ||
setComponent(entity, TransformComponent) | ||
/** Add a mesh to the object */ | ||
const bubbleMesh = new Mesh(new SphereGeometry(), new MeshStandardMaterial()) | ||
bubbleMesh.material.color = new Color(0xFFFFFF) | ||
addObjectToGroup(entity, bubbleMesh) // Add GroupComponent and add mesh to Group | ||
bubbleMesh.material.color = new Color(0xffffff) | ||
addObjectToGroup(entity, bubbleMesh) | ||
}, []) | ||
|
||
return null | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ComponentShelfCategories } from '@etherealengine/editor/src/components/element/ElementList' | ||
import { EntityNodeEditor } from '@etherealengine/editor/src/functions/ComponentEditors' | ||
import { BubbleEmitterComponent } from '../components/BubbleEmitterComponent' | ||
import { BubbleNodeEditor } from './BubbleComponentNodeEditor' | ||
|
||
EntityNodeEditor.set(BubbleEmitterComponent, BubbleNodeEditor) | ||
ComponentShelfCategories.Misc.push(BubbleEmitterComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
import { ComponentShelfCategories } from '@etherealengine/editor/src/components/element/ElementList' | ||
import { EntityNodeEditor } from '@etherealengine/editor/src/functions/ComponentEditors' | ||
import { getState } from "@etherealengine/hyperflux"; | ||
import { BubbleEmitterComponent } from "./components/BubbleEmitterComponent"; | ||
import { BubbleNodeEditor } from "./editors/BubbleComponentNodeEditor"; | ||
import { BubbleSystem } from "./systems/BubbleSystem"; | ||
import { isClient } from '@etherealengine/common/src/utils/getEnvironment'; | ||
import { EngineState } from '@etherealengine/spatial/src/EngineState'; | ||
import { isClient } from '@etherealengine/common/src/utils/getEnvironment' | ||
|
||
export default async function worldInjection() { | ||
if (isClient) { | ||
if (getState(EngineState).isEditing) | ||
{ | ||
EntityNodeEditor.set(BubbleEmitterComponent, BubbleNodeEditor) | ||
ComponentShelfCategories.Misc.push(BubbleEmitterComponent) | ||
} | ||
} | ||
} | ||
/** Ensure bubble system is imported */ | ||
import './systems/BubbleSystem' | ||
|
||
export { BubbleSystem } | ||
/** Ensure bubble editor is imported only on the client */ | ||
if (isClient) import('./editors/RegisterBubbleEditor') | ||
|
||
export default async function worldInjection() {} |