package avatarCfg

import (
	"server/gamedata"
	"server/pkg/github.com/name5566/leaf/log"
	"strconv"
)

const (
	CFG_AVATAR = "Avatar"
)

func init() {
	gamedata.InitCfg(CFG_AVATAR)
}

func GetInitList() []int {
	data, err := gamedata.GetData(CFG_AVATAR)
	if err != nil {
		log.Debug("GetInitList err: %v", err)
		return nil
	}
	r := make([]int, 0, len(data))
	for k, v := range data {
		IsInit := gamedata.GetIntValue(v, "Init")
		if IsInit == 1 {
			k, _ := strconv.Atoi(k)
			r = append(r, k)
		}
	}
	return r
}

func CheckExist(Id int) bool {
	data, err := gamedata.GetData(CFG_AVATAR)
	if err != nil {
		log.Debug("CheckExist err: %v", err)
		return false
	}
	_, ok := data[strconv.Itoa(Id)]
	return ok
}

func GetAllId() []int {
	data, err := gamedata.GetData(CFG_AVATAR)
	if err != nil {
		log.Debug("GetAllId err: %v", err)
		return nil
	}
	r := make([]int, 0, len(data))
	for k := range data {
		Id, _ := strconv.Atoi(k)
		r = append(r, Id)
	}
	return r
}
