Browse Source

Added some new background creation fields

main
Unbewohnte 4 years ago committed by GitHub
parent
commit
f7e8062097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      OBM.go
  2. 4
      manager/beatmap.go
  3. 12
      settings/settings.go
  4. 8
      settings/structure.go
  5. 4
      util/background.go
  6. 2
      worker.go

10
OBM.go

@ -15,8 +15,8 @@ import (
type result struct {
beatmapName string
numberOfDiffs uint
successful uint64
failed uint64
successful uint
failed uint
}
type job struct {
@ -49,8 +49,8 @@ func main() {
SETTINGS := settings.Get()
// creating black image
if SETTINGS.CreateBlackBGImage {
err := util.CreateBlackBG(1920, 1080)
if SETTINGS.CreateBlackBGImage.Enabled {
err := util.CreateBlackBG(SETTINGS.CreateBlackBGImage.Width, SETTINGS.CreateBlackBGImage.Height)
if err == nil {
logger.LogInfo("Successfully created black background")
} else {
@ -82,7 +82,7 @@ func main() {
close(results)
// extracting results and logging the last message
var successful, failed uint64 = 0, 0
var successful, failed uint = 0, 0
for result := range results {
successful += result.successful
failed += result.failed

4
manager/beatmap.go

@ -53,7 +53,7 @@ func (BEATMAP *Beatmap) GetBackgroundName(mapName string) (string, error) {
// parses each beatmap`s .osu file for background info;
// removes original background and replaces it with copied version of given image
func (BEATMAP *Beatmap) ReplaceBackgrounds(replacementPicPath string) (successful, failed uint64) {
func (BEATMAP *Beatmap) ReplaceBackgrounds(replacementPicPath string) (successful, failed uint) {
// looping through each .osu file of a beatmap
for _, diff := range BEATMAP.Diffs {
background, err := BEATMAP.GetBackgroundName(diff)
@ -83,7 +83,7 @@ func (BEATMAP *Beatmap) ReplaceBackgrounds(replacementPicPath string) (successfu
}
// retrieves backgrounds from given beatmap folder (same as in `ReplaceBackgrounds`) and copies them to the retrievement path
func (BEATMAP *Beatmap) RetrieveBackgrounds(retrievementPath string) (successful, failed uint64) {
func (BEATMAP *Beatmap) RetrieveBackgrounds(retrievementPath string) (successful, failed uint) {
// looping through each .osu file of a beatmap
for _, diff := range BEATMAP.Diffs {
background, err := BEATMAP.GetBackgroundName(diff)

12
settings/settings.go

@ -30,7 +30,7 @@ func DoesExist() (bool, error) {
return false, nil
}
// creates "settings.json" and sets the flag
// creates "settings.json" in current directory
func Create() error {
exists, err := DoesExist()
if err != nil {
@ -56,14 +56,18 @@ func Create() error {
Enabled: false,
RetrievementPath: "",
},
CreateBlackBGImage: true,
Workers: 100,
CreateBlackBGImage: creatingBG{
Enabled: true,
Width: 1920,
Height: 1080,
},
Workers: 100,
}, "", " ")
if err != nil {
return errors.New(fmt.Sprintf("Could not marshal settings into file : %s", err))
}
file.Write(settingsJson)
file.Write(settingsJson)
file.Close()
return nil

8
settings/structure.go

@ -14,11 +14,17 @@ type backgroundRetrievement struct {
RetrievementPath string `json:"retrievementPath"`
}
type creatingBG struct {
Enabled bool `json:"enabled"`
Width uint `json:"width"`
Height uint `json:"height"`
}
// struct for json settings` file contents
type Settings struct {
OsuDir string `json:"pathToOsu"`
BackgroundReplacement backgroundReplacement `json:"backgroundReplacement"`
BackgroundRetrievement backgroundRetrievement `json:"backgroundRetrievement"`
CreateBlackBGImage bool `json:"createBlackBackgoundImage"`
CreateBlackBGImage creatingBG `json:"createBlackBackgoundImage"`
Workers int `json:"workers"`
}

4
util/background.go

@ -10,12 +10,12 @@ import (
)
// creates a complete black image file
func CreateBlackBG(width, height int) error {
func CreateBlackBG(width, height uint) error {
bgfile, err := os.Create("blackBG.png")
if err != nil {
return errors.New(fmt.Sprintf("Could not create black background file : %s", err))
}
image := image.NewRGBA(image.Rect(0, 0, width, height))
image := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
bounds := image.Bounds()
for y := 0; y < bounds.Max.Y; y++ {

2
worker.go

@ -8,7 +8,7 @@ import (
func worker(jobs <-chan job, results chan result, WG *sync.WaitGroup) {
defer WG.Done()
for job := range jobs {
var successful, failed uint64 = 0, 0
var successful, failed uint = 0, 0
if job.retrievementPath != "" {
s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath)

Loading…
Cancel
Save