package faceCfg

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

const (
	CFG_FACE = "Face"
)

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

func GetInitList() []int {
	data, err := gamedata.GetData(CFG_FACE)
	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 {
			id, err := strconv.Atoi(k)
			if err != nil {
				log.Debug("GetInitList parse id err:%v, key=%s", err, k)
				continue
			}
			r = append(r, id)
		}
	}
	return r
}

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

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