NateTheGreatt/bitECS

provide ablity to check whether component field addresses eid

caryoscelus opened this issue · 2 comments

a bit of context: i'm dealing with serialization rn, and find builtin serialization mechanism lacking in documentation. i'm getting some arraybuffer, but have no idea of its format. i haven't dug too far, but it does look like it's a binary format. i would like to have text-based serialization as alternative, so i'm building my own. with a bit of customizing defineComponent (along the lines of #111 (comment)), i'm able to jsonify entities, but in order to make proper (de)serialization i need to handle eids

it seems like whether a store contains eids or not can be determined by $isEidType field, but that symbol doesn't seem to be available for library users. can we have some way to query this information from outside library internals?

You can use this "trick" to retrieve bitecs internal symbols:

const $isEidType= Object.getOwnPropertySymbols(Component.property).find(
	(symbol) => symbol.toString() === Symbol('isEidType').toString(),
) as symbol;

It works also on world and on components.

@pietrovismara this seems a bit too hacky to be reliable: anything not in API can be changed without warning. for now i simply forked repo to use in the project where i need this, but having official solution would still be better