private void ReplaceCharacter(CollectionReplaceEvent <int> prop) { int charId = prop.NewValue; Sprite sprite; if (!CharacterFaceSpriteProvider.Instance.TryGetSprite(charId, out sprite)) { return; } Character data; if (!CharacterMasterDataProvider.Instance.TryGetData(charId, out data)) { return; } Color color; if (!ElementFrameColorProvider.Instance.TryGetColor(data.ElementType, out color)) { return; } _view.SetCharacterFace(sprite); _view.SetElementFrame(color); }
public override ApplicationResult Apply(KSEQOperation <T> op, bool quiet = false) { // Retrieve the newest queued set for the given ID if the item already exists, performing an insert with its // id iif the id is later, and using the appropriate value. if (op.op == KSEQOperationTypes.Insert && m_QueuedSet.ContainsKey(op.value.id)) { var replacementOp = m_QueuedSet[op.value.id]; if (op.id < replacementOp.id) { throw new ArgumentException( $"op {op} has an ident with precedence over a set but matching id {op.value.id}", nameof(op)); } m_QueuedSet.Remove(op.value.id); op.value = replacementOp.value; op.id = replacementOp.id; } var handled = base.Apply(op, quiet); if (handled.applied) { switch (op.op) { // Worst case: O(N) (op to the beginning of the list // Best case: O(1) (op to the end of the list) case KSEQOperationTypes.Insert: m_IdToIndex[op.value.id] = handled.index; for (var i = handled.index + 1; i < Count; i++) { m_IdToIndex[m_AtomList[i].value.id] = i; } break; case KSEQOperationTypes.Remove: m_IdToIndex.Remove(op.value.id); m_RemovedIds.Remove(op.value.id); for (var i = handled.index; i < Count; i++) { m_IdToIndex[m_AtomList[i].value.id] = i; } break; } return(handled); } switch (op.op) { case KSEQOperationTypes.Set: if (m_RemovedIds.Contains(op.value.id) || m_Removed.Contains(op.id)) { break; } // Find an existing record. Otherwise, queue up if (m_IdToIndex.ContainsKey(op.value.id)) { var i = m_IdToIndex[op.value.id]; var atom = m_AtomList[i]; var originalValue = atom.value; if (originalValue.id != op.value.id) { throw new ArgumentException($"invalid set, {op.value.id}!={originalValue.id}"); } // If this is later (last write first), go ahead and replace the atom with the new value. // Otherwise, do nothing. if (op.id < atom.id) { var oldAtom = atom; atom.id = op.id; atom.value = op.value; Remove(oldAtom.id); var j = Add(op.id, op.value); for (var k = Math.Min(i, j); k <= Math.Max(i, j); k++) { m_IdToIndex[m_AtomList[k].value.id] = k; } if (!quiet) { var collectionReplaceEvent = new CollectionReplaceEvent <T>(i, originalValue, op.value); collectionReplace?.OnNext( collectionReplaceEvent); if (i != j) { collectionMove?.OnNext(new CollectionMoveEvent <T>(i, j, op.value)); } if (op.replicaId == replicaId) { collectionThisReplicaReplaced?.OnNext(collectionReplaceEvent); } } } return(new ApplicationResult() { applied = true, index = i }); } else { if (!m_QueuedSet.ContainsKey(op.value.id) || (m_QueuedSet.ContainsKey(op.value.id) && op.id < m_QueuedSet[op.value.id].id)) { // Only replace the existing queued set if this op is later m_QueuedSet[op.value.id] = op; } return(new ApplicationResult() { applied = true }); } } return(new ApplicationResult()); }
// private methods private void RefreshView(CollectionReplaceEvent <bool> prop) { _view.SetVisible(prop.NewValue); }
// private methods private void RefreshView(CollectionReplaceEvent <bool> prop) { bool selected = prop.NewValue; _view.SetVisible(selected); }