func fetchMissionTarget(targetKey string) (*entities.Planet, *response.StateChange, error) {
	targetEntity, err := entities.Get(targetKey)
	if err != nil {
		return nil, nil, err
	}
	target := targetEntity.(*entities.Planet)
	target.UpdateShipCount()

	stateChange := response.NewStateChange()
	stateChange.RawPlanets = map[string]*entities.Planet{
		target.Key(): target,
	}
	clients.Broadcast(target)

	return target, stateChange, nil
}
示例#2
0
// Add a change to the stateChange
func (c *Client) pushStateChange(entity entities.Entity) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	if c.stateChange == nil {
		c.stateChange = response.NewStateChange()
	}

	switch e := entity.(type) {
	case *entities.Mission:
		c.stateChange.Missions[e.Key()] = e
	case *entities.Planet:
		c.stateChange.RawPlanets[e.Key()] = e
	case *entities.Sun:
		c.stateChange.Suns[e.Key()] = e
	}
}