Conversation
|
Wow @hmans - we make a great team. 😄 Thanks for your help! Check out the updated PR. Seems to work great. entity-typings.mp4Here are the docs: What do you think? |
|
This is pretty close to my land. I do have custom physics components that get introduced once you import our Jolt physics library: github.com/gamebop/physics It will create multiple new components, like 'body'. I just had to suck up the errors, since, I concured I am in minority of users who introduce new components to the system. However, I am aware of the strides towards supporting custom addons/components and was holding off till closed beta is out. My library will definitely benefit from this PR. Good motion! Also worth mentioning that a factory component could add Debug asserts for supplied properties. We do it to spot any unrecognized properties, mostly due to typos. A component may throw a warning if a property is not recognized, or values are out of acceptable range. |
|
@LeXXik Wow, that physics library looks really cool! Nice job! @hmans I do have one concern about something. Before adding support for custom components, if you tried to add an invalid property to the options object, IntelliSense would show a red line under that property and log an error in the PROBLEMS panel. Now, if you do that, IntelliSense thinks it's just a custom component. Hmmm. I'm wondering if we can say a custom component is a string but NOT any of the keyof ComponentMap values. |
Yeah, this is the one caveat I was writing about in my post. I have some more ideas for stuff I want to try to improve this. I won't be able to get to it until later tonight, but maybe we can figure something out. My main issue that's slowing me down right now is that I'm having a hard time figuring out a speedy development/testing flow for this. I'm diving into this codebase for the first time, and it's also the first time I am working with jsdoc types (as opposed to plain old TS, which I'm very familiar with.) So far, the only way I've found to get my changes to Right now I'm trying the changes from within the test scripts in the engine project, |
|
Technically we should have everything that's needed from this point: createOptions.componentSystems = [
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ScriptComponentSystem,
pc.AnimComponentSystem
];Then just do some type voodoo. Minimal example with a new component: class OceanComponent {}
class OceanComponentData {}
class OceanComponentSystem extends ComponentSystem {
/** @type {'ocean'} */
id = 'ocean';
ComponentType = OceanComponent;
DataType = OceanComponentData;
}
const systems = [OceanComponentSystem];
console.log("systems", systems);
/**
* @typedef {{
* [S in (typeof systems)[number] as InstanceType<S>['id']]: InstanceType<InstanceType<S>['ComponentType']>
* }} ComponentMap
*/So we get the actual types we are using: Instead of simply registering every PC system. Why would I even want types for e.g. |







At the moment, the Entity API has reasonably weak typings. This PR improves the situation, particularly for
addComponent.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.