Example #1
0
func (cs *consoleScreen) onKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if key == glfw.KeyGraveAccent && action == glfw.Release {
		cs.visible = false
		window.SetKeyCallback(cs.prevKey)
		window.SetCharCallback(cs.prevChar)
		cs.input = cs.input[:len(cs.input)-1]
	}
	if key == glfw.KeyBackspace && action != glfw.Release {
		if len(cs.input) > 0 {
			cs.input = cs.input[:len(cs.input)-1]
		}
	}
	if key == glfw.KeyEnter && action == glfw.Release {
		console.Component(format.
			Build("> ").
			Color(format.Yellow).
			Append(cs.input).
			Create(),
		)
		err := console.Execute(cs.input)
		cs.input = ""
		if err != nil {
			console.Component(format.
				Build("Error").
				Color(format.Red).
				Append(": ").
				Color(format.Yellow).
				Append(err.Error()).
				Color(format.Red).
				Create(),
			)
		}
	}
}
Example #2
0
File: conf.go Project: num5/steven
// ExecConf executes/loads the passed config file
func ExecConf(path string) {
	// The config file needs special rights
	if path == "conf.cfg" {
		configOverride = true
	}
	defer func() {
		if path == "conf.cfg" {
			configOverride = false
			saveConf()
		}
	}()
	f, err := os.Open(path)
	if err != nil {
		Component(format.Build("Failed to open ").
			Append(path).
			Append(": ").
			Append(err.Error()).
			Create(),
		)
		return
	}
	defer f.Close()
	s := bufio.NewScanner(f)
	for s.Scan() {
		txt := strings.TrimSpace(s.Text())
		if strings.HasPrefix(txt, "#") || txt == "" {
			continue
		}
		if err := Execute(txt); err != nil {
			Component(format.Build("Error: " + err.Error()).Color(format.Red).Create())
		}
	}
}
Example #3
0
File: cvar.go Project: num5/steven
func (c *cvar) printDoc() {
	for _, line := range strings.Split(c.documentation, "\n") {
		Component(format.Build("# ").
			Color(format.DarkGray).
			Append(line).
			Color(format.Gray).
			Create())
	}
}
Example #4
0
File: cvar.go Project: num5/steven
func (i *IntVar) print() {
	Component(format.Build(i.name).
		Color(format.Aqua).
		Append(" ").
		Append(fmt.Sprint(i.value)).
		Color(format.Aqua).
		Create(),
	)
}
Example #5
0
File: cvar.go Project: num5/steven
func (s *StringVar) print() {
	Component(format.Build(s.name).
		Color(format.Aqua).
		Append(" ").
		Append("\"").Color(format.Yellow).
		Append(s.value).
		Color(format.Aqua).
		Append("\"").Color(format.Yellow).
		Create(),
	)
}
Example #6
0
File: cvar.go Project: num5/steven
func (b *BoolVar) print() {
	col := format.Red
	if b.value {
		col = format.Green
	}
	Component(format.Build(b.name).
		Color(format.Aqua).
		Append(" ").
		Append(fmt.Sprint(b.value)).
		Color(col).
		Create(),
	)
}
Example #7
0
File: audio.go Project: num5/steven
func playSoundInternal(cat soundCategory, snd sound, vol, pitch float64, rel bool, pos mgl32.Vec3, cb func()) {
	vol *= snd.Volume * 100
	baseVol := vol
	vol *= float64(muVolMaster.Value()) / 100
	if v, ok := volVars[cat]; ok {
		vol *= float64(v.Value()) / 100
	}
	if vol <= 0 {
		if cb != nil {
			go func() { syncChan <- cb }()
		}
		return
	}
	name := snd.Name
	key := pluginKey{"minecraft", name}
	sb, ok := loadedSounds[key]
	if !ok {
		f, err := resource.Open("minecraft", "sounds/"+name+".ogg")
		if err != nil {
			v, ok := assets.Objects[fmt.Sprintf("minecraft/sounds/%s.ogg", name)]
			if !ok {
				console.Text("Missing sound %s", key)
				if cb != nil {
					cb()
				}
				return
			}
			loc := fmt.Sprintf("./resources/%s", hashPath(v.Hash))
			f, err = os.Open(loc)
			if err != nil {
				console.Text("Missing sound %s", key)
				if cb != nil {
					cb()
				}
				return
			}
		}
		if snd.Stream {
			m := audio.NewMusic(f)
			m.SetVolume(vol)
			m.SetPitch(pitch)
			m.Play()
			currentMusic = append(currentMusic, music{Music: m, cb: cb, cat: cat, vol: baseVol})
			return
		}
		defer f.Close()
		data, err := ioutil.ReadAll(f)
		if err != nil {
			panic(err)
		}
		sb = audio.NewSoundBufferData(data)
		loadedSounds[key] = sb
	}
	var s audio.Sound
	n := true
	for _, sn := range soundList {
		if sn.Status() == audio.StatStopped {
			s = sn
			n = false
			break
		}
	}
	if n {
		if len(soundList) >= 100 {
			console.Component(
				format.Build("WARN: Skipping playing sound due to limit").
					Color(format.Yellow).Create(),
			)
			return
		}
		s = audio.NewSound()
		soundList = append(soundList, s)
	}
	s.SetBuffer(sb)
	s.SetVolume(vol)
	s.SetMinDistance(5)
	s.SetAttenuation(0.008)
	s.SetPitch(pitch)
	s.Play()
	if rel {
		s.SetRelative(true)
		s.SetPosition(pos.X(), pos.Y(), pos.Z())
	} else {
		s.SetRelative(false)
	}
}