func nyfikenc() (err error) { // Connect to nyfikend. conn, err := net.Dial("tcp", "localhost"+settings.Global.PortNum) if err != nil { if e, ok := err.(*net.OpError); ok { if e.Err.Error() == "getsockopt: connection refused" { return errutil.NewNoPos("nyfikenc: unable to connect to nyfikend. Please make sure that the daemon is running.") } } else { return err } } bw := bufioutil.NewWriter(conn) // Command-line flag check if flagRecheck || flagClearAll || flagReadAndClearAll || flagReadAll { if flagRecheck { return force(&bw) } if flagClearAll { return clearAll(&bw, conn) } if flagReadAll { return readAll(&bw, conn) } if flagReadAndClearAll { err = readAll(&bw, conn) if err != nil { return err } return clearAll(&bw, conn) } } // If no updates where found -> apologize. ups, err := getUpdates(&bw, conn) if err != nil { return errutil.Err(err) } lenUps := len(ups) if lenUps == 0 { fmt.Println("Sorry, no updates :(") os.Exit(ErrNodata) return nil } for up := range ups { fmt.Printf("%s\n", up) } return nil }
func update(buf audio.PCM32Samples, dec audio.Decoder) error { n, err := dec.Read(buf) if err != nil { return err } fmt.Println(len(buf), n) if n == 0 { return errutil.NewNoPos("EOF") } // The x scale is relative to the number of frames. xscale := len(buf) / width // The y scale is relative to the range of values from the frames. yscale := Range(buf) / height i := image.NewRGBA(image.Rect(0, 0, width, height)) draw.Draw(i, i.Bounds(), &image.Uniform{black}, image.ZP, draw.Src) oldx, oldy := 0, height/2 for x := 0; x < width; x += 2 { // loudness from the frame scaled down to the image. loudness := int(buf[x*xscale]) / (yscale + 1) // To center the oscilloscope on the y axis we add height/2. y := loudness + height/2 // draw a line between (x, y) and (oldx, oldy) line(i, x, y, oldx, oldy) // Update old x/y. oldx, oldy = x, y } // Change image.Image type to win.Image. img, err := win.ReadImage(i) if err != nil { return errutil.Err(err) } // Draw image to window. err = win.Draw(image.ZP, img) if err != nil { return errutil.Err(err) } // Display window updates on screen. return win.Update() }
// newGame initalizes a new game session. func newGame(a *area.Area) error { // *a = gen.AreaPrim(100, 30) *a = gen.Area(100, 30) gen.Mobs(a, 16) gen.Items(a, 20) gen.Objects(a, 50) // Hero starting position. var ok bool creature.Hero, ok = creature.Beastiary["hero"] if !ok { return errutil.NewNoPos("unable to locate hero in creatures.") } creature.Hero.SetX(a.Width / 2) creature.Hero.SetY(a.Height / 2) a.Monsters[creature.Hero.Coord()] = &creature.Hero return nil }