MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Block

Class Block

src/main/java/fieldkotlin/ElasticAnimation.kt:56–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55
56 class Block(
57 var start: Int = 0,
58 var startConstraint: ((Block?, Block, List<Block>) -> Int)? = null,
59 var duration: Int = -1,
60 var durationConstraint: ((Block?, Block, List<Block>) -> Int)? = null,
61 val name: String = "",
62 val apply: suspend SequenceScope<Any>.() -> Unit
63 ) {
64 // children for the purposes of figuring out the duration
65 // start of these is relative to the start of this
66 val childrenDuration = mutableListOf<Block>()
67 val childrenStart = mutableListOf<Block>()
68 val children = mutableListOf<Block>()
69
70 var parent: Block? = null
71
72
73 var effectiveStart = 0
74
75 var seq = sequence(apply).iterator()
76
77 fun reset() {
78 seq = sequence(apply).iterator()
79 }
80
81 fun and(b: BlockBuilder.() -> Unit): Block {
82 BlockBuilder(this).apply(b)
83 return this
84 }
85
86 fun preFixDurations() {
87 startConstraint?.let {
88// if (childrenStart.size > 0)
89 start = it(parent, this, childrenStart)
90 }
91 }
92
93 fun postFixDurations() {
94 durationConstraint?.let {
95 duration = it(parent, this, childrenDuration)
96 if (duration < 0) duration = 0
97 }
98
99 }
100
101 fun runAtTime(realTime: Double): Boolean {
102 _block.set(null)
103 time = realTime
104 return inBlock(this) {
105 if (!seq.hasNext())
106 false
107 else {
108 seq.next()
109 true
110 }
111 }
112 }
113

Callers 4

blockMethod · 0.85
thenMethod · 0.85
blocksMethod · 0.85
runMethod · 0.85

Calls 1

iteratorMethod · 0.45

Tested by

no test coverage detected