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 { type result struct {
beatmapName string beatmapName string
numberOfDiffs uint numberOfDiffs uint
successful uint64 successful uint
failed uint64 failed uint
} }
type job struct { type job struct {
@ -49,8 +49,8 @@ func main() {
SETTINGS := settings.Get() SETTINGS := settings.Get()
// creating black image // creating black image
if SETTINGS.CreateBlackBGImage { if SETTINGS.CreateBlackBGImage.Enabled {
err := util.CreateBlackBG(1920, 1080) err := util.CreateBlackBG(SETTINGS.CreateBlackBGImage.Width, SETTINGS.CreateBlackBGImage.Height)
if err == nil { if err == nil {
logger.LogInfo("Successfully created black background") logger.LogInfo("Successfully created black background")
} else { } else {
@ -82,7 +82,7 @@ func main() {
close(results) close(results)
// extracting results and logging the last message // extracting results and logging the last message
var successful, failed uint64 = 0, 0 var successful, failed uint = 0, 0
for result := range results { for result := range results {
successful += result.successful successful += result.successful
failed += result.failed 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; // parses each beatmap`s .osu file for background info;
// removes original background and replaces it with copied version of given image // 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 // looping through each .osu file of a beatmap
for _, diff := range BEATMAP.Diffs { for _, diff := range BEATMAP.Diffs {
background, err := BEATMAP.GetBackgroundName(diff) 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 // 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 // looping through each .osu file of a beatmap
for _, diff := range BEATMAP.Diffs { for _, diff := range BEATMAP.Diffs {
background, err := BEATMAP.GetBackgroundName(diff) background, err := BEATMAP.GetBackgroundName(diff)

12
settings/settings.go

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

8
settings/structure.go

@ -14,11 +14,17 @@ type backgroundRetrievement struct {
RetrievementPath string `json:"retrievementPath"` 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 // struct for json settings` file contents
type Settings struct { type Settings struct {
OsuDir string `json:"pathToOsu"` OsuDir string `json:"pathToOsu"`
BackgroundReplacement backgroundReplacement `json:"backgroundReplacement"` BackgroundReplacement backgroundReplacement `json:"backgroundReplacement"`
BackgroundRetrievement backgroundRetrievement `json:"backgroundRetrievement"` BackgroundRetrievement backgroundRetrievement `json:"backgroundRetrievement"`
CreateBlackBGImage bool `json:"createBlackBackgoundImage"` CreateBlackBGImage creatingBG `json:"createBlackBackgoundImage"`
Workers int `json:"workers"` Workers int `json:"workers"`
} }

4
util/background.go

@ -10,12 +10,12 @@ import (
) )
// creates a complete black image file // creates a complete black image file
func CreateBlackBG(width, height int) error { func CreateBlackBG(width, height uint) error {
bgfile, err := os.Create("blackBG.png") bgfile, err := os.Create("blackBG.png")
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Could not create black background file : %s", err)) 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() bounds := image.Bounds()
for y := 0; y < bounds.Max.Y; y++ { 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) { func worker(jobs <-chan job, results chan result, WG *sync.WaitGroup) {
defer WG.Done() defer WG.Done()
for job := range jobs { for job := range jobs {
var successful, failed uint64 = 0, 0 var successful, failed uint = 0, 0
if job.retrievementPath != "" { if job.retrievementPath != "" {
s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath) s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath)

Loading…
Cancel
Save