Пример #1
0
func (pm *placeMine) Respond(gid game.Gid, group gin.EventGroup) bool {
	if found, event := group.FindEvent(gin.AnySpace); found && event.Type == gin.Press {
		pm.fire++
		return true
	}
	return false
}
Пример #2
0
func (rw *riftWalk) Respond(gid game.Gid, group gin.EventGroup) bool {
	if found, event := group.FindEvent(gin.AnySpace); found && event.Type == gin.Press {
		rw.trigger = true
		return true
	}
	return false
}
Пример #3
0
func (l *LocalData) handleEventGroupArchitect(group gin.EventGroup) {
	keys := []gin.KeyId{gin.AnyKey1, gin.AnyKey2, gin.AnyKey3, gin.AnyKey4, gin.AnyKey5, gin.AnyKey6, gin.AnyKey7, gin.AnyKey8, gin.AnyKey9}
	for i := range l.architect.abs.abilities {
		if found, event := group.FindEvent(keys[i]); found && event.Type == gin.Press {
			l.activateAbility(&l.architect.abs, "", i, true)
		}
	}
	if l.architect.abs.activeAbility != nil {
		l.architect.abs.activeAbility.Respond("", group)
	}
}
Пример #4
0
func (l *LocalData) handleEventGroupInvaders(group gin.EventGroup) {
	if l.mode != LocalModeMoba {
		panic("Need to implement controls for multiple players on a single screen")
	}
	k0 := gin.In().GetKeyFlat(gin.Key6, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k1 := gin.In().GetKeyFlat(gin.Key7, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k2 := gin.In().GetKeyFlat(gin.Key8, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k3 := gin.In().GetKeyFlat(gin.Key9, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	if found, event := group.FindEvent(k0.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 0, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k1.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 1, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k2.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 2, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k3.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 3, event.Type == gin.Press)
		return
	}
	if l.moba.currentPlayer.abs.activeAbility != nil {
		if l.moba.currentPlayer.abs.activeAbility.Respond(l.moba.currentPlayer.gid, group) {
			return
		}
	}
}
Пример #5
0
func (b *Button) Respond(eventGroup gin.EventGroup) {
	// Only respond to mouse events if the mouse is hovering over the button
	if !b.Hover && eventGroup.Events[0].Key.Id().Device.Type == gin.DeviceTypeMouse {
		return
	}
	if found, event := eventGroup.FindEvent(gin.AnyMouseLButton); found && event.Type == gin.Press {
		if b.Callback != nil {
			b.Callback()
		}
		return
	}
	for trigger := range b.Triggers {
		if found, event := eventGroup.FindEvent(trigger); found && event.Type == gin.Press {
			if b.Callback != nil {
				b.Callback()
			}
			return
		}
	}
}
Пример #6
0
func (game *Game) HandleEventGroupSetup(group gin.EventGroup) {
	if found, event := group.FindEvent(control.hat.up.Id()); found && event.Type == gin.Press {
		game.Setup.local.Lock()
		defer game.Setup.local.Unlock()
		if game.Setup.local.Index > 0 {
			game.Setup.local.Index--
		}
		return
	}
	if found, event := group.FindEvent(control.hat.down.Id()); found && event.Type == gin.Press {
		game.Setup.local.Lock()
		defer game.Setup.local.Unlock()
		if game.Setup.local.Index < len(game.Setup.EngineIds) {
			game.Setup.local.Index++
		}
		return
	}

	if found, event := group.FindEvent(control.hat.left.Id()); found && event.Type == gin.Press {
		game.local.Engine.ApplyEvent(SetupChampSelect{game.local.Engine.Id(), -1})
		return
	}
	if found, event := group.FindEvent(control.hat.right.Id()); found && event.Type == gin.Press {
		game.local.Engine.ApplyEvent(SetupChampSelect{game.local.Engine.Id(), 1})
		return
	}
	if found, event := group.FindEvent(control.hat.enter.Id()); found && event.Type == gin.Press {
		game.Setup.local.Lock()
		defer game.Setup.local.Unlock()
		if game.Setup.local.Index < len(game.Setup.EngineIds) {
			id := game.Setup.EngineIds[game.Setup.local.Index]
			side := (game.Setup.Players[id].Side + 1) % 2
			game.local.Engine.ApplyEvent(SetupChangeSides{id, side})
		} else {
			if game.local.Engine.Id() == game.Manager || game.local.Engine.IsHost() {
				game.local.Engine.ApplyEvent(SetupComplete{time.Now().UnixNano()})
			}
		}
		return
	}
}
Пример #7
0
func (tsm *ThunderSubMenu) Respond(eventGroup gin.EventGroup) {
	var up, down bool
	for _, keyIndex := range tsm.downs {
		id := gin.In().GetKeyFlat(keyIndex, gin.DeviceTypeAny, gin.DeviceIndexAny).Id()
		if found, event := eventGroup.FindEvent(id); found && event.Type == gin.Press {
			down = true
		}
	}
	for _, keyIndex := range tsm.ups {
		id := gin.In().GetKeyFlat(keyIndex, gin.DeviceTypeAny, gin.DeviceIndexAny).Id()
		if found, event := eventGroup.FindEvent(id); found && event.Type == gin.Press {
			up = true
		}
	}
	if down {
		tsm.selected++
	}
	if up {
		if tsm.selected == -1 {
			tsm.selected = len(tsm.Options) - 1
		} else {
			tsm.selected--
		}
	}
	if tsm.selected >= len(tsm.Options) || tsm.selected < 0 {
		tsm.selected = -1
	}
	if eventGroup.Events[0].Key.Id().Device.Type != gin.DeviceTypeMouse {
		if tsm.selected >= 0 && tsm.selected < len(tsm.Options) {
			tsm.Options[tsm.selected].Respond(eventGroup)
		}
	} else {
		for _, option := range tsm.Options {
			option.Respond(eventGroup)
		}
	}
}
Пример #8
0
func (g *Game) HandleEventGroupEditor(group gin.EventGroup) {
	g.editor.Lock()
	defer g.editor.Unlock()

	if found, event := group.FindEvent(control.editor.Id()); found && event.Type == gin.Press {
		// Can't call editor.Toggle() here because we already hold the lock.
		g.editor.active = false
		g.editor.action = editorActionNone
		return
	}

	if found, event := group.FindEvent(gin.AnyKeyB); found && event.Type == gin.Press {
		g.editor.placeBlockAction()
		return
	}

	if found, event := group.FindEvent(gin.AnyKeyS); found && event.Type == gin.Press {
		g.editor.saveAction(&g.Level.Room)
		return
	}

	if found, event := group.FindEvent(gin.AnyKeyP); found && event.Type == gin.Press {
		g.editor.pathingAction()
		return
	}

	switch g.editor.action {
	case editorActionNone:
		return
	case editorActionPlaceBlock:
		if found, event := group.FindEvent(gin.AnyMouseLButton); found && event.Type == gin.Press {
			g.editor.placeBlockDo(g)
			return
		}
	}
}
Пример #9
0
func (g *Game) HandleEventGroupGame(group gin.EventGroup) {
	g.local.RLock()
	defer g.local.RUnlock()

	if found, event := group.FindEvent(control.editor.Id()); found && event.Type == gin.Press {
		g.editor.Toggle()
		return
	}

	if found, _ := group.FindEvent(control.any.Id()); found {
		dir := getControllerDirection(gin.DeviceId{gin.DeviceTypeController, gin.DeviceIndexAny})
		g.local.Engine.ApplyEvent(&Move{
			Gid:       g.local.Gid,
			Angle:     dir.Angle(),
			Magnitude: dir.Mag(),
		})
	}

	// ability0Key := gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny)
	// abilityTrigger := gin.In().GetKeyFlat(gin.ControllerButton0+1, gin.DeviceTypeController, gin.DeviceIndexAny)
	buttons := []gin.Key{
		gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+3, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+4, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+5, gin.DeviceTypeController, gin.DeviceIndexAny),
	}
	abilityTrigger := gin.In().GetKeyFlat(gin.ControllerButton0+6, gin.DeviceTypeController, gin.DeviceIndexAny)
	for i, button := range buttons {
		foundButton, _ := group.FindEvent(button.Id())
		foundTrigger, triggerEvent := group.FindEvent(abilityTrigger.Id())
		// TODO: Check if any abilities are Active before sending events to other abilities.
		if foundButton || foundTrigger {
			g.local.Engine.ApplyEvent(UseAbility{
				Gid:     g.local.Gid,
				Index:   i,
				Button:  button.CurPressAmt(),
				Trigger: foundTrigger && triggerEvent.Type == gin.Press,
			})
		}
	}
}