func (cm *CraftModel) AddArchetype(a *Archetype) { qml.Lock() cm.Craftables = append(cm.Craftables, &CraftElement{Archetype: a, Ready: false}) cm.Len = len(cm.Craftables) qml.Changed(cm, &cm.Len) qml.Unlock() }
func (im *InventoryModel) SlotUpdated(index int) { // For now we ignore that a slot is updated and just reset the whole thing. Lazy, and slower, I know! qml.Lock() im.Size -= 1 qml.Changed(im, &im.Size) im.Size += 1 qml.Changed(im, &im.Size) qml.Unlock() build_model.Update(im.Entity.EntityID) }
func (jm *JobModel) Update() { qml.Lock() jm.Len = len(w.Jobs) jm.Jobs = make([]*kinglib.JobStatus, jm.Len) count := 0 for _, js := range w.Jobs { jm.Jobs[count] = js count++ } // fmt.Printf("JobModel Length: %d\n", jm.Len) qml.Unlock() qml.Changed(jm, &jm.Len) }
func (bm *BuildModel) Update(entity_id int) { qml.Lock() bm.Entity = w.Entities[entity_id] record := make(map[*Archetype]int) if bm.Entity != nil { // These first two lines ensure that a complete redraw is performed: bm.Size -= 1 qml.Changed(bm, &bm.Size) // Check how many inventory items are buildable: count := 0 for _, e := range bm.Entity.Inventory.Slots { if e != nil { a := w.Archetypes[e.SimpleName] if a.Buildable { record[a] += e.Quantity count++ } } } bm.Size = len(record) bm.Slots = make([]*BuildSlot, len(record)) count = 0 for a, q := range record { bm.Slots[count] = &BuildSlot{count, a, q} count++ } // for _, e := range bm.Entity.Inventory.Slots { // if e != nil && w.Archetypes[e.SimpleName].Buildable { // bm.Slots[count] = &BuildSlot{count, w.Archetypes[e.SimpleName], e.Quantity} // count++ // } // } } else { bm.Size = 0 bm.Slots = make([]*BuildSlot, 0) } qml.Changed(bm, &bm.Size) qml.Unlock() }
func (im *InventoryModel) SetContainer(entity_id int) { // This function should only be called once whenever the vessel is set. Vessel is the entity which represents the player qml.Lock() im.Entity = w.Entities[entity_id] if im.Entity != nil { // These first two lines ensure that a complete redraw is performed: im.Size -= 1 qml.Changed(im, &im.Size) im.Size = len(im.Entity.Inventory.Slots) im.Slots = make([]*InventorySlot, im.Size) for i, _ := range im.Slots { im.Slots[i] = &InventorySlot{} } } else { im.Size = 0 im.Slots = make([]*InventorySlot, 0) } qml.Changed(im, &im.Size) qml.Unlock() build_model.Update(entity_id) }