new room gui

This commit is contained in:
Aynakeya
2022-11-28 18:39:12 -08:00
parent eac8b7b775
commit 0498d2dbf3
38 changed files with 1368 additions and 324 deletions

View File

@@ -8,7 +8,7 @@ import (
const (
ProgramName = "卡西米尔唱片机"
Version = "beta 0.9.2"
Version = "beta 0.9.3"
)
const (
@@ -22,6 +22,17 @@ func GetAssetPath(name string) string {
type Config interface {
Name() string
OnLoad()
OnSave()
}
type BaseConfig struct {
}
func (c *BaseConfig) OnLoad() {
}
func (c *BaseConfig) OnSave() {
}
var ConfigFile *ini.File
@@ -32,6 +43,7 @@ func LoadConfig(cfg Config) {
if err == nil {
_ = sec.MapTo(cfg)
}
cfg.OnLoad()
Configs = append(Configs, cfg)
return
}
@@ -43,7 +55,7 @@ func init() {
fmt.Println("config not found, using default config")
ConfigFile = ini.Empty()
}
for _, cfg := range []Config{Log, LiveRoom, Player, Provider, General} {
for _, cfg := range []Config{Log, Player, Provider, General} {
LoadConfig(cfg)
}
}
@@ -51,6 +63,7 @@ func init() {
func SaveToConfigFile(filename string) error {
cfgFile := ini.Empty()
for _, cfg := range Configs {
cfg.OnSave()
if err := cfgFile.Section(cfg.Name()).ReflectFrom(cfg); err != nil {
fmt.Println(err)
}

View File

@@ -1,6 +1,7 @@
package config
type _GeneralConfig struct {
BaseConfig
Language string
}

View File

@@ -1,11 +0,0 @@
package config
type _LiveRoomConfig struct {
History []string
}
func (c *_LiveRoomConfig) Name() string {
return "LiveRoom"
}
var LiveRoom = &_LiveRoomConfig{History: []string{"9076804", "3819533"}}

View File

@@ -8,6 +8,12 @@ type _LogConfig struct {
RedirectStderr bool
}
func (c *_LogConfig) OnLoad() {
}
func (c *_LogConfig) OnSave() {
}
func (c *_LogConfig) Name() string {
return "Log"
}

View File

@@ -1,25 +1,55 @@
package config
type _PlayerConfig struct {
Playlists []string
PlaylistsProvider []string
PlaylistIndex int
PlaylistRandom bool
AudioDevice string
Volume float64
SkipPlaylist bool
PlaylistData string
Playlists []*PlayerPlaylist `ini:"-"`
//PlaylistsProvider []string
PlaylistIndex int
PlaylistRandom bool
UserPlaylistRandom bool
AudioDevice string
Volume float64
SkipPlaylist bool
}
type PlayerPlaylist struct {
ID string
Provider string
}
func (c *_PlayerConfig) Name() string {
return "Player"
}
var Player = &_PlayerConfig{
Playlists: []string{"2382819181", "4987059624", "list1"},
PlaylistsProvider: []string{"netease", "netease", "local"},
PlaylistIndex: 0,
PlaylistRandom: true,
AudioDevice: "auto",
Volume: 100,
SkipPlaylist: false,
func (c *_PlayerConfig) OnLoad() {
//c.Playlists = make([]*PlayerPlaylist, 0)
_ = LoadJson(c.PlaylistData, &c.Playlists)
}
func (c *_PlayerConfig) OnSave() {
_ = SaveJson(c.PlaylistData, &c.Playlists)
}
var Player = &_PlayerConfig{
PlaylistData: "playlists.json",
Playlists: []*PlayerPlaylist{
{
"2382819181",
"netease",
},
{
"4987059624",
"netease",
},
{
"list1",
"local",
},
},
PlaylistIndex: 0,
PlaylistRandom: true,
UserPlaylistRandom: false,
AudioDevice: "auto",
Volume: 100,
SkipPlaylist: false,
}

View File

@@ -1,6 +1,7 @@
package config
type _ProviderConfig struct {
BaseConfig
Priority []string
LocalDir string
}

23
config/jsonconfig.go Normal file
View File

@@ -0,0 +1,23 @@
package config
import (
"encoding/json"
"os"
)
func LoadJson(path string, dst any) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
return json.Unmarshal(data, dst)
}
func SaveJson(path string, dst any) error {
data, err := json.MarshalIndent(dst, "", " ")
if err != nil {
return err
}
return os.WriteFile(path, data, 0666)
}