Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <A> nz.sodium.Cell<Option<A>> watchEntityComponentOp(
- nz.sodium.Cell<Option<EcsReadOnlySceneContext>> cSceneCtxOp,
- nz.sodium.Stream<EcsSceneChanges> sSceneChanges,
- int entityId,
- EcsComponent<A> ecsComponent
- ) {
- nz.sodium.StreamLoop<Option<A>> slEntityComponentOp = new sodium.StreamLoop<>();
- nz.sodium.Cell<Option<A>> cEntityComponentOp =
- slEntityComponentOp
- .hold(
- cSceneCtxOp.sample()
- .bind(
- (EcsReadOnlySceneContext sceneCtx) ->
- sceneCtx.getComponent(entityId, ecsComponent)
- )
- );
- slEntityComponentOp.loop(
- sodium.Stream.filterOptional(
- sSceneChanges.snapshot(
- cEntityComponentOp,
- cSceneCtxOp,
- (EcsSceneChanges sceneChanges, Option<A> entityComponentOp, Option<EcsReadOnlySceneContext> sceneCtxOp) -> {
- Option<Option<A>> _nextEntityComponentOpOp = Option.none();
- for (EcsSceneChange sceneChange : sceneChanges.changes()) {
- Option<Option<A>> lastEntityComponentOpOp = _nextEntityComponentOpOp;
- _nextEntityComponentOpOp = sceneChange.match(new EcsSceneChange.CasesAdapter<Option<Option<A>>>(lastEntityComponentOpOp) {
- @Override
- public Option<Option<A>> newScene() {
- return sceneCtxOp.map((EcsReadOnlySceneContext sceneCtx) -> sceneCtx.getComponent(entityId, ecsComponent));
- }
- @Override
- public Option<Option<A>> setComponents(int entityId2, EcsComponentValue[] components) {
- if (entityId2 != entityId) {
- return lastEntityComponentOpOp;
- }
- for (EcsComponentValue componentValue : components) {
- for (A component : componentValue.value(ecsComponent)) {
- return Option.some(Option.some(component));
- }
- }
- return lastEntityComponentOpOp;
- }
- @Override
- public Option<Option<A>> unsetComponents(int entityId2, EcsComponentType[] componentTypes) {
- if (entityId2 != entityId) {
- return lastEntityComponentOpOp;
- }
- for (EcsComponentType componentType : componentTypes) {
- if (componentType.equals(ecsComponent.type())) {
- return Option.some(Option.none());
- }
- }
- return lastEntityComponentOpOp;
- }
- });
- }
- return fj.data.Java8.Option_Optional(_nextEntityComponentOpOp);
- }
- )
- )
- );
- return cEntityComponentOp;
- }
Add Comment
Please, Sign In to add comment