2023-10-31 22:40:14 +00:00
|
|
|
package person
|
|
|
|
|
|
|
|
import (
|
2023-11-01 01:24:42 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-10-31 22:40:14 +00:00
|
|
|
"github.com/ectrc/snow/storage"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Item struct {
|
2023-11-05 01:58:00 +00:00
|
|
|
ID string
|
|
|
|
ProfileID string
|
|
|
|
TemplateID string
|
|
|
|
Quantity int
|
|
|
|
Favorite bool
|
|
|
|
HasSeen bool
|
|
|
|
Variants []*VariantChannel
|
2023-10-31 22:40:14 +00:00
|
|
|
ProfileType string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewItem(templateID string, quantity int) *Item {
|
|
|
|
return &Item{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: uuid.New().String(),
|
2023-10-31 22:40:14 +00:00
|
|
|
TemplateID: templateID,
|
2023-11-05 01:58:00 +00:00
|
|
|
Quantity: quantity,
|
|
|
|
Favorite: false,
|
|
|
|
HasSeen: false,
|
|
|
|
Variants: []*VariantChannel{},
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 23:19:52 +00:00
|
|
|
func NewItemWithType(templateID string, quantity int, profile string) *Item {
|
|
|
|
return &Item{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: uuid.New().String(),
|
2023-10-31 23:19:52 +00:00
|
|
|
TemplateID: templateID,
|
2023-11-05 01:58:00 +00:00
|
|
|
Quantity: quantity,
|
|
|
|
Favorite: false,
|
|
|
|
HasSeen: false,
|
|
|
|
Variants: []*VariantChannel{},
|
2023-10-31 23:19:52 +00:00
|
|
|
ProfileType: profile,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
func FromDatabaseItem(item *storage.DB_Item) *Item {
|
2023-10-31 22:40:14 +00:00
|
|
|
variants := []*VariantChannel{}
|
|
|
|
|
|
|
|
for _, variant := range item.Variants {
|
|
|
|
variants = append(variants, FromDatabaseVariant(&variant))
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Item{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: item.ID,
|
|
|
|
TemplateID: item.TemplateID,
|
|
|
|
Quantity: item.Quantity,
|
|
|
|
Favorite: item.Favorite,
|
|
|
|
HasSeen: item.HasSeen,
|
|
|
|
Variants: variants,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromDatabaseLoot(item *storage.DB_Loot) *Item {
|
|
|
|
return &Item{
|
|
|
|
ID: item.ID,
|
|
|
|
TemplateID: item.TemplateID,
|
|
|
|
Quantity: item.Quantity,
|
|
|
|
Favorite: false,
|
|
|
|
HasSeen: false,
|
|
|
|
Variants: []*VariantChannel{},
|
|
|
|
ProfileType: item.ProfileType,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 01:24:42 +00:00
|
|
|
func (i *Item) GenerateFortniteItemEntry() aid.JSON {
|
2023-11-05 22:08:53 +00:00
|
|
|
attributes := aid.JSON{
|
2023-11-20 21:20:26 +00:00
|
|
|
"variants": i.GenerateFortniteItemVariantChannels(),
|
2023-11-05 22:08:53 +00:00
|
|
|
"favorite": i.Favorite,
|
|
|
|
"item_seen": i.HasSeen,
|
|
|
|
}
|
2023-11-01 01:24:42 +00:00
|
|
|
|
2023-11-05 22:08:53 +00:00
|
|
|
if i.TemplateID == "Currency:MtxPurchased" {
|
|
|
|
attributes = aid.JSON{
|
|
|
|
"platform": "Shared",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 01:24:42 +00:00
|
|
|
return aid.JSON{
|
|
|
|
"templateId": i.TemplateID,
|
2023-11-05 22:08:53 +00:00
|
|
|
"attributes": attributes,
|
2023-11-01 01:24:42 +00:00
|
|
|
"quantity": i.Quantity,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 21:20:26 +00:00
|
|
|
func (i *Item) GenerateFortniteItemVariantChannels() []aid.JSON {
|
|
|
|
variants := []aid.JSON{}
|
|
|
|
|
|
|
|
for _, variant := range i.Variants {
|
|
|
|
variants = append(variants, aid.JSON{
|
|
|
|
"channel": variant.Channel,
|
|
|
|
"owned": variant.Owned,
|
|
|
|
"active": variant.Active,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return variants
|
|
|
|
}
|
|
|
|
|
2023-11-01 01:24:42 +00:00
|
|
|
func (i *Item) GetAttribute(attribute string) interface{} {
|
|
|
|
switch attribute {
|
|
|
|
case "Favorite":
|
|
|
|
return i.Favorite
|
|
|
|
case "HasSeen":
|
|
|
|
return i.HasSeen
|
|
|
|
case "Variants":
|
|
|
|
return i.Variants
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func (i *Item) Delete() {
|
2023-11-01 21:33:25 +00:00
|
|
|
storage.Repo.DeleteItem(i.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) DeleteLoot() {
|
|
|
|
storage.Repo.DeleteLoot(i.ID)
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) NewChannel(channel string, owned []string, active string) *VariantChannel {
|
|
|
|
return &VariantChannel{
|
2023-11-05 01:58:00 +00:00
|
|
|
ItemID: i.ID,
|
2023-10-31 22:40:14 +00:00
|
|
|
Channel: channel,
|
2023-11-05 01:58:00 +00:00
|
|
|
Owned: owned,
|
|
|
|
Active: active,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) AddChannel(channel *VariantChannel) {
|
|
|
|
i.Variants = append(i.Variants, channel)
|
|
|
|
//storage.Repo.SaveItemVariant(i.ID, channel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) RemoveChannel(channel *VariantChannel) {
|
|
|
|
for index, c := range i.Variants {
|
|
|
|
if c.Channel == channel.Channel {
|
|
|
|
i.Variants = append(i.Variants[:index], i.Variants[index+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//storage.Repo.DeleteItemVariant(i.ID, channel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) GetChannel(channel string) *VariantChannel {
|
|
|
|
for _, c := range i.Variants {
|
|
|
|
if c.Channel == channel {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) FillChannels(channels []*VariantChannel) {
|
|
|
|
i.Variants = []*VariantChannel{}
|
|
|
|
for _, channel := range channels {
|
|
|
|
i.AddChannel(channel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) ToDatabase(profileId string) *storage.DB_Item {
|
|
|
|
variants := []storage.DB_VariantChannel{}
|
|
|
|
|
|
|
|
for _, variant := range i.Variants {
|
|
|
|
variants = append(variants, *variant.ToDatabase())
|
|
|
|
}
|
|
|
|
|
|
|
|
return &storage.DB_Item{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: i.ID,
|
2023-12-17 00:43:17 +00:00
|
|
|
ProfileID: profileId,
|
2023-10-31 22:40:14 +00:00
|
|
|
TemplateID: i.TemplateID,
|
2023-11-05 01:58:00 +00:00
|
|
|
Quantity: i.Quantity,
|
|
|
|
Favorite: i.Favorite,
|
|
|
|
HasSeen: i.HasSeen,
|
|
|
|
Variants: variants,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) Save() {
|
2023-11-05 01:58:00 +00:00
|
|
|
if i.ProfileID == "" {
|
|
|
|
aid.Print("error saving item", i.ID, "no profile id")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Repo.SaveItem(i.ToDatabase(i.ProfileID))
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) ToLootDatabase(giftId string) *storage.DB_Loot {
|
|
|
|
return &storage.DB_Loot{
|
2023-11-05 01:58:00 +00:00
|
|
|
GiftID: giftId,
|
2023-10-31 22:40:14 +00:00
|
|
|
ProfileType: i.ProfileType,
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: i.ID,
|
|
|
|
TemplateID: i.TemplateID,
|
|
|
|
Quantity: i.Quantity,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) SaveLoot(giftId string) {
|
|
|
|
//storage.Repo.SaveLoot(i.ToLootDatabase(giftId))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Item) Snapshot() ItemSnapshot {
|
|
|
|
variants := []VariantChannel{}
|
|
|
|
|
|
|
|
for _, variant := range i.Variants {
|
|
|
|
variants = append(variants, *variant)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ItemSnapshot{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: i.ID,
|
|
|
|
TemplateID: i.TemplateID,
|
|
|
|
Quantity: i.Quantity,
|
|
|
|
Favorite: i.Favorite,
|
|
|
|
HasSeen: i.HasSeen,
|
|
|
|
Variants: variants,
|
2023-10-31 22:40:14 +00:00
|
|
|
ProfileType: i.ProfileType,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type VariantChannel struct {
|
2023-11-01 21:33:25 +00:00
|
|
|
ID string
|
2023-10-31 22:40:14 +00:00
|
|
|
ItemID string
|
|
|
|
Channel string
|
|
|
|
Owned []string
|
|
|
|
Active string
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromDatabaseVariant(variant *storage.DB_VariantChannel) *VariantChannel {
|
|
|
|
return &VariantChannel{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: variant.ID,
|
|
|
|
ItemID: variant.ItemID,
|
2023-10-31 22:40:14 +00:00
|
|
|
Channel: variant.Channel,
|
2023-11-05 01:58:00 +00:00
|
|
|
Owned: variant.Owned,
|
|
|
|
Active: variant.Active,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VariantChannel) ToDatabase() *storage.DB_VariantChannel {
|
|
|
|
return &storage.DB_VariantChannel{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: v.ID,
|
|
|
|
ItemID: v.ItemID,
|
2023-10-31 22:40:14 +00:00
|
|
|
Channel: v.Channel,
|
2023-11-05 01:58:00 +00:00
|
|
|
Owned: v.Owned,
|
|
|
|
Active: v.Active,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VariantChannel) Save() {
|
|
|
|
//storage.Repo.SaveItemVariant(v.ToDatabase())
|
|
|
|
}
|