package Ġcom . so yle . stories . use case . repositories Ċ Ċ import Ġcom . so yle . stories . domain . character . Character Ċ import Ġcom . so yle . stories . domain . location . Location Ċ import Ġcom . so yle . stories . domain . project . Project Ċ import Ġcom . so yle . stories . domain . pro se . Pro se Ċ import Ġcom . so yle . stories . domain . scene . Scene Ċ import Ġcom . so yle . stories . domain . story event . Story Event Ċ import Ġcom . so yle . stories . domain . theme . Symbol Ċ import Ġcom . so yle . stories . use case . scene . Scene Repository Ċ Ċ class ĠScene Repository Double ( Ċ ĉ initial Sc enes : ĠList < Scene > Ġ= Ġempty List (), ĊĊ ĉ private Ġval Ġon AddNew Scene : Ġ( Scene ) Ġ-> ĠUnit Ġ= Ġ{}, Ċ ĉ private Ġval ĠonUpdate Scene Order : Ġ( Project . Id , ĠList < Scene . Id >) Ġ-> ĠUnit Ġ= Ġ{ Ġ_, Ġ_ Ġ-> Ġ}, Ċ ĉ private Ġval ĠonUpdate Scene : Ġ( Scene ) Ġ-> ĠUnit Ġ= Ġ{}, Ċ ĉ private Ġval Ġon Remove Scene : Ġ( Scene ) Ġ-> ĠUnit Ġ= Ġ{} Ċ ) Ġ: ĠScene Repository Ġ{ ĊĊ ĉ val Ġscenes Ġ= Ġinitial Sc enes . associate By Ġ{ Ġit . id Ġ}. to Mutable Map () Ċ ĉ val Ġscene Order Ġ= Ġinitial Sc enes . groupBy Ġ{ Ġit . projectId Ġ}. map Values Ġ{ Ġit . value . map ( Scene :: id ) Ġ}. to Mutable Map () ĊĊ ĉ fun Ġgiven Scene ( scene : ĠScene ) Ċ ĉ { Ċĉ ĉ scenes [ scene . id ] Ġ= Ġscene Ċĉ ĉ scene Order [ scene . projectId ] Ġ= Ġscene Order [ scene . projectId ]?. plus ( scene . id ) Ġ?: ĠlistOf ( scene . id ) Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġcreate New Scene ( scene : ĠScene , Ġid Order : ĠList < Scene . Id >) Ġ{ Ċĉ ĉ on AddNew Scene . invoke ( scene ) Ċĉ ĉ scenes [ scene . id ] Ġ= Ġscene Ċĉ ĉ scene Order [ scene . projectId ] Ġ= Ġid Order Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġlist All Sc enes In Project ( projectId : ĠProject . Id , Ġexclude : ĠSet < Scene . Id >): ĠList < Scene > Ġ{ Ċĉ ĉ return Ġscenes . values . filter Ġ{ Ġit . projectId Ġ== ĠprojectId Ġ&& Ġit . id Ġ! in Ġexclude Ġ} Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Scene Ids In Order ( projectId : ĠProject . Id ): ĠList < Scene . Id > Ġ{ Ċĉ ĉ return Ġscene Order [ projectId ] Ġ?: Ġempty List () Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġupdate Scene Order ( projectId : ĠProject . Id , Ġorder : ĠList < Scene . Id >) Ġ{ Ċĉ ĉ on Update Scene Order . invoke ( projectId , Ġorder ) Ċĉ ĉ scene Order [ projectId ] Ġ= Ġorder Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Scene ById ( scene Id : ĠScene . Id ): ĠScene ? Ġ= ĊĉĠ Ġscenes [ scene Id ] ĊĊ ĉ override Ġsuspend Ġfun Ġget Scene For Story Event ( story EventId : ĠStory Event . Id ): ĠScene ? Ġ{ Ċĉ ĉ return Ġscenes . values . find Ġ{ Ġit . story EventId Ġ== Ġstory EventId Ġ} Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Scene That Ow ns Pro se ( pro se Id : ĠPro se . Id ): ĠScene ? Ġ{ Ċĉ ĉ return Ġscenes . values . find Ġ{ Ġit . pro se Id Ġ== Ġpro se Id Ġ} Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġupdate Scene ( scene : ĠScene ) Ġ{ Ċĉ ĉ on Update Scene . invoke ( scene ) Ċĉ ĉ scenes [ scene . id ] Ġ= Ġscene Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġremove Scene ( scene : ĠScene ) Ġ{ Ċĉ ĉ scenes . remove ( scene . id ) Ċĉ ĉ on Remove Scene . invoke ( scene ) Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Sc enes Tracking Symbol ( symbol Id : ĠSymbol . Id ): ĠList < Scene > Ġ{ Ċĉ ĉ return Ġscenes . values . filter Ġ{ Ġit . tracked Symbols . is Symbol Tracked ( symbol Id ) Ġ} Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Sc enes Using Location ( location Id : ĠLocation . Id ): ĠList < Scene > Ġ{ Ċĉ ĉ return Ġscenes . values . filter Ġ{ Ġit . settings . contains Entity With Id ( location Id ) Ġ} Ċ ĉ } ĊĊ ĉ override Ġsuspend Ġfun Ġget Sc enes In cluding Character ( character Id : ĠCharacter . Id ): ĠList < Scene > Ġ{ Ċĉ ĉ return Ġscenes . values . filter Ġ{ Ġit . includes Character ( character Id ) Ġ} Ċ ĉ } Ċ Ċ }