import { Quaternion } from "three" ; import { ThingType , Place } from "./types" ; import { Slot } from "./slot" ; export class Thing { index : number ; type : ThingType ; typeIndex : number ; slot : Slot ; rotationIndex : number ; claimedBy : number | null ; readonly heldRotation : Quaternion ; shiftSlot : Slot | null ; lastShiftSlot : Slot | null ; lastShiftSlotTime : number ; sent : boolean ; constructor ( index , type , typeIndex , slot ) { this . index = index ; this . type = type ; this . typeIndex = typeIndex ; this . slot = slot ; this . rotationIndex = 0 ; this . claimedBy = null ; this . heldRotation = new Quaternion ( ) ; this . shiftSlot = null ; this . lastShiftSlot = null ; this . lastShiftSlotTime = 0 ; this . sent = false ; this . slot . thing = this ; } place ( ) { return this . slot . placeWithOffset ( this . rotationIndex ) ; } flip ( rotationIndex ? ) { if ( rotationIndex === undefined ) { rotationIndex = this . rotationIndex + 1 ; } const r = this . slot . rotations . length ; this . rotationIndex = ( rotationIndex + r ) % r ; this . sent = false ; } prepareMove ( ) { this . slot . thing = null ; } moveTo ( target , rotationIndex ? ) { if ( target . thing !== null ) { throw `slot not empty: ${ this . index } ${ target . name }` ; } this . slot = target ; this . rotationIndex = rotationIndex ?? 0 ; target . thing = this ; this . sent = false ; } hold ( seat ) { this . claimedBy = seat ; this . heldRotation . copy ( this . place ( ) . rotation ) ; this . sent = false ; } shiftTo ( seat , slot ) { this . claimedBy = seat ; this . shiftSlot = slot ; this . sent = false ; } release ( ) { this . claimedBy = null ; this . shiftSlot = null ; this . sent = false ; } }