goosr

package module
v0.0.0-...-7939beb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 12 Imported by: 0

README

go-osr

An osu! replay parser for Golang inspired by node-osr

Installation

go get github.com/robloxxa/go-osr

Documentation

Examples

Read replay from file
package main

import (
	"fmt"
	"github.com/robloxxa/go-osr"
)

func main() {
	r, err := goosr.NewReplayFromFile("replay.osr")
	if err != nil {
		panic(err)
	}
	fmt.Println(r)
}

or

package main

import (
	"fmt"
	"github.com/robloxxa/go-osr"
)

func main() {
	r := goosr.NewReplay()
	data := []byte{} // Some data in binary
	err := r.Unmarshal(data)
	if err != nil {
		panic(err)
	}
	fmt.Println(r)
}
Write replay data to file
package main

import (
	"fmt"
	"github.com/robloxxa/go-osr"
)

func main() {
	r, err := goosr.NewReplayFromFile("replay.osr")
	if err != nil {
		panic(err)
	}
	r.CountMiss = 1 // Change some data from parsed replay
	err = r.WriteToFile("replay.osr")
	if err != nil {
		panic(err)
	}
}

or

package main

import (
	"github.com/robloxxa/go-osr"
	"io/fs"
	"os"
)

func main() {
	r, err := goosr.NewReplayFromFile("replay.osr")
	if err != nil {
		panic(err)
	}
	r.CountMiss = 1 // Change some data from parsed replay
	b, err := r.Marshal()
	if err != nil {
		panic(err)
	}
	err = os.WriteFile("replay.osr", b, fs.ModePerm)
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	OSU = iota
	TAIKO
	CTB
	MANIA
)
View Source
const (
	MOUSELEFT = 1 << iota
	MOUSERIGHT
	K1
	K2
	SMOKE
)

Variables

View Source
var ModsEnum = []BanchoMod{
	{0, "NM", "NoMod"},
	{1, "NF", "NoFail"},
	{2, "EZ", "Easy"},
	{4, "TD", "TouchDevice"},
	{8, "HD", "Hidden"},
	{16, "HR", "HardRock"},
	{32, "SD", "SuddenDeath"},
	{64, "DT", "DoubleTime"},
	{128, "RX", "Relax"},
	{256, "HT", "HalfTime"},
	{512, "NC", "NightCore"},
	{1024, "FL", "Flashlight"},
	{2048, "AT", "Auto"},
	{4096, "SO", "SpunOut"},
	{8192, "AP", "AutoPilot"},
	{16384, "PF", "Perfect"},
}

Functions

func ParseGamemode

func ParseGamemode(i int8) string

func ReturnBitFlags

func ReturnBitFlags(mods []BanchoMod) (i uint32)

ReturnBitFlags iterate through BanchoMod slice and returns a bit value

Types

type BanchoMod

type BanchoMod struct {
	Value uint32
	Short string
	Long  string
}

func ParseBitFlags

func ParseBitFlags(bits uint32) (mods []BanchoMod)

ParseBitFlags parses an osu! mods bit values and return an BanchoMod slice

type CompressedReplay

type CompressedReplay []byte

func (*CompressedReplay) Decompress

func (cr *CompressedReplay) Decompress() (dr DecompressedReplay, err error)

Decompress a ReplayData to DecompressedReplay slice

type DecompressedReplay

type DecompressedReplay []ReplayValue

func (*DecompressedReplay) Compress

func (dr *DecompressedReplay) Compress() (cr CompressedReplay)

Compress a DecompressedReplay slice to CompressedReplay byte slice

type KeyPressed

type KeyPressed struct {
	MouseLeft  bool
	MouseRight bool
	K1         bool
	K2         bool
	Smoke      bool
}

type Replay

type Replay struct {
	Gamemode      int8
	Version       int32
	BeatmapMD5    string
	PlayerName    string
	ReplayMD5     string
	Count300      uint16
	Count100      uint16
	Count50       uint16
	CountGeki     uint16
	CountKatu     uint16
	CountMiss     uint16
	TotalScore    int32
	Combo         int16
	PerfectCombo  bool
	Mods          uint32
	LifeBarGraph  string
	TimeStamp     time.Time
	ReplayData    CompressedReplay
	OnlineScoreID int64
	AdditionalMod float64
}

func NewReplay

func NewReplay() (r *Replay)

NewReplay returns an empty Replay struct with TimeStamp

func NewReplayFromFile

func NewReplayFromFile(path string) (r *Replay, err error)

NewReplayFromFile reads a replay file, parses it and returns a Replay pointer

func (*Replay) Marshal

func (r *Replay) Marshal() (b []byte, err error)

Marshal encodes Replay struct to byte slice

func (*Replay) String

func (r *Replay) String() (s string)

Formats Replay struct to string

func (*Replay) Unmarshal

func (r *Replay) Unmarshal(data []byte) (err error)

Unmarshal decode byte array to Replay struct

func (*Replay) WriteToFile

func (r *Replay) WriteToFile(path string) (err error)

WriteToFile writes a replay file to specified path

type ReplayValue

type ReplayValue struct {
	Ms         int64
	X          float32
	Y          float32
	KeyPressed KeyPressed
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL