Guest User

Untitled

a guest
Oct 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. public static <A> nz.sodium.Cell<Option<A>> watchEntityComponentOp(
  2. nz.sodium.Cell<Option<EcsReadOnlySceneContext>> cSceneCtxOp,
  3. nz.sodium.Stream<EcsSceneChanges> sSceneChanges,
  4. int entityId,
  5. EcsComponent<A> ecsComponent
  6. ) {
  7. nz.sodium.StreamLoop<Option<A>> slEntityComponentOp = new sodium.StreamLoop<>();
  8. nz.sodium.Cell<Option<A>> cEntityComponentOp =
  9. slEntityComponentOp
  10. .hold(
  11. cSceneCtxOp.sample()
  12. .bind(
  13. (EcsReadOnlySceneContext sceneCtx) ->
  14. sceneCtx.getComponent(entityId, ecsComponent)
  15. )
  16. );
  17. slEntityComponentOp.loop(
  18. sodium.Stream.filterOptional(
  19. sSceneChanges.snapshot(
  20. cEntityComponentOp,
  21. cSceneCtxOp,
  22. (EcsSceneChanges sceneChanges, Option<A> entityComponentOp, Option<EcsReadOnlySceneContext> sceneCtxOp) -> {
  23. Option<Option<A>> _nextEntityComponentOpOp = Option.none();
  24. for (EcsSceneChange sceneChange : sceneChanges.changes()) {
  25. Option<Option<A>> lastEntityComponentOpOp = _nextEntityComponentOpOp;
  26. _nextEntityComponentOpOp = sceneChange.match(new EcsSceneChange.CasesAdapter<Option<Option<A>>>(lastEntityComponentOpOp) {
  27. @Override
  28. public Option<Option<A>> newScene() {
  29. return sceneCtxOp.map((EcsReadOnlySceneContext sceneCtx) -> sceneCtx.getComponent(entityId, ecsComponent));
  30. }
  31. @Override
  32. public Option<Option<A>> setComponents(int entityId2, EcsComponentValue[] components) {
  33. if (entityId2 != entityId) {
  34. return lastEntityComponentOpOp;
  35. }
  36. for (EcsComponentValue componentValue : components) {
  37. for (A component : componentValue.value(ecsComponent)) {
  38. return Option.some(Option.some(component));
  39. }
  40. }
  41. return lastEntityComponentOpOp;
  42. }
  43. @Override
  44. public Option<Option<A>> unsetComponents(int entityId2, EcsComponentType[] componentTypes) {
  45. if (entityId2 != entityId) {
  46. return lastEntityComponentOpOp;
  47. }
  48. for (EcsComponentType componentType : componentTypes) {
  49. if (componentType.equals(ecsComponent.type())) {
  50. return Option.some(Option.none());
  51. }
  52. }
  53. return lastEntityComponentOpOp;
  54. }
  55. });
  56. }
  57. return fj.data.Java8.Option_Optional(_nextEntityComponentOpOp);
  58. }
  59. )
  60. )
  61. );
  62. return cEntityComponentOp;
  63. }
Add Comment
Please, Sign In to add comment