repo for my hex addons :3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

handle concept moving sanely

+22 -14
+22 -14
project/hexic/src/main/scala/org/eu/net/pool/hexic/views.scala
··· 33 33 import org.slf4j.{Logger, LoggerFactory} 34 34 35 35 import java.util.UUID 36 + import scala.annotation.tailrec 36 37 import scala.collection.immutable.ArraySeq.unsafeWrapArray 37 38 import scala.collection.mutable 38 39 import scala.reflect.ClassTag 39 - import scala.util.{Failure, Success, Using} 40 + import scala.util.{Failure, Success, Using, boundary} 40 41 41 42 trait InventoryView(val viewType: InventoryView.Type[?]) extends InventoryView.Handler: 42 43 def isTruthy = true ··· 284 285 setConceptScale[SingletonVariant.heat.type](20) 285 286 Patterns.register("moveconcept", se"wawdwawqdewewedqwawdwaw"): 286 287 Patterns.mkConstAction(4): 287 - case Seq(isIota[BoxedView.Instance, 3](from), isIota[BoxedView.Instance, 2](into), typ: VariantIota[?], isIota[DoubleIota, 0](count)) => 288 - Using.resource(Transaction.openOuter()): 288 + case Seq(isIota[BoxedView.Instance, 3](BoxedView.Instance(from)), isIota[BoxedView.Instance, 2](BoxedView.Instance(into)), typ: VariantIota[?], isIota[DoubleIota, 0](count)) => 289 + val key = ClassTag(typ.data.getClass) 290 + val scale = conceptScale(key) 291 + @tailrec def negotiate(limit: Long): Seq[Iota] = 292 + val compromise = Using.resource(Transaction.openOuter()): 293 + case tx@given TransactionContext => 294 + val extracted = (from: InventoryView).tryExtract((typ: VariantIota[?]).data, limit) 295 + val inserted = (into: InventoryView).tryInsert((typ: VariantIota[?]).data, extracted) 296 + if extracted == inserted then 297 + tx.commit() 298 + return Seq(DoubleIota(inserted / scale)) 299 + else 300 + inserted 301 + negotiate(compromise) 302 + val initialLimit = Using.resource(Transaction.openOuter()): 289 303 case tx@given TransactionContext => 290 - val key = ClassTag(typ.data.getClass) 291 - val scale = conceptScale(key) 292 - val toExtract = (scale * count.getDouble).toLong 293 - val extract = from.view.tryExtract(typ.data, toExtract) 294 - if extract < toExtract then 295 - ??? // TODO: mishap 296 - val insert = into.view.tryInsert(typ.data, extract) 297 - if insert < extract then 298 - ??? // TODO: mishap 299 - tx.commit() 300 - Seq(DoubleIota(insert / scale)) 304 + val value = (into: InventoryView).tryInsert(typ.data, (scale * count.getDouble).toLong) 305 + tx.abort() 306 + value 307 + negotiate(initialLimit) 308 + 301 309 Patterns.register("moveentity", se"edeeewawdweaaddaqwqwqaddaaewdwawewdqd"): 302 310 Patterns.mkConstAction(3): 303 311 case Seq(isIota[BoxedView.Instance, 2](from), isIota[BoxedView.Instance, 1](into), isIota[DoubleIota, 0](count)) =>