New initializes the CameraSystem. New initializes the CameraSystem.
(w *ecs.World)
| 65 | // New initializes the CameraSystem. |
| 66 | // New initializes the CameraSystem. |
| 67 | func (cam *CameraSystem) New(w *ecs.World) { |
| 68 | num := 0 |
| 69 | for _, sys := range w.Systems() { |
| 70 | switch sys.(type) { |
| 71 | case *CameraSystem: |
| 72 | num++ |
| 73 | } |
| 74 | } |
| 75 | if num > 0 { //initalizer is called before added to w.systems |
| 76 | warning("More than one CameraSystem was added to the World. The RenderSystem adds a CameraSystem if none exist when it's added.") |
| 77 | } |
| 78 | |
| 79 | if CameraBounds.Max.X == 0 && CameraBounds.Max.Y == 0 { |
| 80 | CameraBounds.Max = engo.Point{X: engo.GameWidth(), Y: engo.GameHeight()} |
| 81 | } |
| 82 | |
| 83 | cam.x = CameraBounds.Max.X / 2 |
| 84 | cam.y = CameraBounds.Max.Y / 2 |
| 85 | cam.z = 1 |
| 86 | |
| 87 | cam.longTasks = make(map[CameraAxis]*CameraMessage) |
| 88 | |
| 89 | engo.Mailbox.Listen("CameraMessage", func(msg engo.Message) { |
| 90 | cammsg, ok := msg.(CameraMessage) |
| 91 | if !ok { |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | // Stop with whatever we're doing now |
| 96 | if _, ok := cam.longTasks[cammsg.Axis]; ok { |
| 97 | delete(cam.longTasks, cammsg.Axis) |
| 98 | } |
| 99 | |
| 100 | if cammsg.Duration > time.Duration(0) { |
| 101 | cam.longTasks[cammsg.Axis] = &cammsg |
| 102 | return // because it's handled incrementally |
| 103 | } |
| 104 | |
| 105 | if cammsg.Incremental { |
| 106 | cam.moveAxis(cammsg.Axis, cammsg.Value) |
| 107 | } else { |
| 108 | cam.moveAxisTo(cammsg.Axis, cammsg.Value) |
| 109 | } |
| 110 | }) |
| 111 | |
| 112 | engo.Mailbox.Dispatch(NewCameraMessage{}) |
| 113 | } |
| 114 | |
| 115 | // Remove does nothing since the CameraSystem has only one entity, the camera itself. |
| 116 | // This is here to implement the ecs.System interface. |
nothing calls this directly
no test coverage detected