From f7e8062097ac94a862e0caa556560899fb7635d9 Mon Sep 17 00:00:00 2001 From: Unbewohnte <65883674+Unbewohnte@users.noreply.github.com> Date: Sun, 2 May 2021 18:28:32 +0300 Subject: [PATCH] Added some new background creation fields --- OBM.go | 10 +++++----- manager/beatmap.go | 4 ++-- settings/settings.go | 12 ++++++++---- settings/structure.go | 8 +++++++- util/background.go | 4 ++-- worker.go | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/OBM.go b/OBM.go index 9f1861f..545d302 100644 --- a/OBM.go +++ b/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 diff --git a/manager/beatmap.go b/manager/beatmap.go index f2d6b28..b15bb6b 100644 --- a/manager/beatmap.go +++ b/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) diff --git a/settings/settings.go b/settings/settings.go index cbafc7e..fd1bfca 100644 --- a/settings/settings.go +++ b/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 diff --git a/settings/structure.go b/settings/structure.go index df5972b..df50a07 100644 --- a/settings/structure.go +++ b/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"` } diff --git a/util/background.go b/util/background.go index 4296d4b..a7f745a 100644 --- a/util/background.go +++ b/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++ { diff --git a/worker.go b/worker.go index e797e7a..e63a65f 100644 --- a/worker.go +++ b/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)