public TagBlockPage CloneValue() { var result = new TagBlockPage(_index, _fields.Length); Array.Copy(_fields, result._fields, _fields.Length); return(result); }
public void UnloadPage() { if (_lastPage != null) { _lastPage.CloneChanges(_loadedFields, _tracker, _changes); } _lastPage = null; }
public FlattenedTagBlock(FlattenedTagBlock parent, TagBlockData template, ObservableCollection <MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes) { _parent = parent; _template = template; _activeTagBlock = template; _synchronizedTagBlocks.Add(template); if (template.HasChildren) { _lastPage = template.Pages[template.CurrentIndex]; } _topLevelFields = topLevelFields; _tracker = tracker; _changes = changes; }
public void ReadTagBlockChildren(TagBlockData block) { if (!block.HasChildren || block.CurrentIndex < 0) { return; } bool opened = OpenReader(); if (_reader == null) { return; } try { // Calculate the base offset to read from long oldBaseOffset = BaseOffset; long dataOffset = block.FirstElementAddress; if (_type == LoadType.File) { dataOffset = (uint)_cache.MetaArea.PointerToOffset(dataOffset); } BaseOffset = (dataOffset + block.CurrentIndex * block.ElementSize); TagBlockPage page = block.Pages[block.CurrentIndex]; for (int i = 0; i < page.Fields.Length; i++) { ReadField(page.Fields[i] ?? block.Template[i]); } BaseOffset = oldBaseOffset; } finally { if (opened) { CloseReader(); } } }
public void LoadPage(TagBlockData block, int index) { _activeTagBlock = block; if (!block.HasChildren) { return; } if (index >= 0 && index < block.Length && block.Pages[index] == _lastPage) { return; } UnloadPage(); if (index < 0 || index >= block.Length) { _lastPage = null; return; } _lastPage = block.Pages[index]; for (int i = 0; i < _lastPage.Fields.Length; i++) { // if _lastPage.Fields[i] is null, then we can just re-use the field from the template MetaField newField; if (_lastPage.Fields[i] != null) { newField = _lastPage.Fields[i]; } else { newField = block.Template[i]; } // HACK: synchronize the opacity newField.Opacity = _loadedFields[i].Opacity; _loadedFields[i] = newField; } }
public void WriteTagBlockChildren(TagBlockData field) { if (field.CurrentIndex < 0 || !field.HasChildren) { return; } // Get the base address and convert it to an offset if we're writing to the file long newBaseOffset = field.FirstElementAddress; if (_type == SaveType.File) { newBaseOffset = _cache.MetaArea.PointerToOffset(newBaseOffset); } // Save the old base offset and set the base offset to the block's base long oldBaseOffset = _baseOffset; _baseOffset = newBaseOffset; // Write each page int _oldIndex = field.CurrentIndex; bool _oldPokeTemplates = _pokeTemplateFields; for (int i = 0; i < field.Length; i++) { // If we're saving everything, then change the active page so the values get loaded from the file if (_changes == null && field.CurrentIndex != i) { field.CurrentIndex = i; } // If we're not saving everything, then we can only poke template fields in block // if the current indices all line up if (i != _oldIndex) { _pokeTemplateFields = false; } // Get each field in the page and write it TagBlockPage page = field.Pages[i]; for (int j = 0; j < page.Fields.Length; j++) { MetaField pageField = page.Fields[j]; // The field in the page takes precedence over the field in the block's template if (pageField == null && (_changes == null || _pokeTemplateFields)) { pageField = field.Template[j]; // Get it from the template } if (pageField != null) { WriteField(pageField); } } // Advance to the next chunk _baseOffset += field.ElementSize; _pokeTemplateFields = _oldPokeTemplates; } if (!Equals(field.CurrentIndex, _oldIndex)) { field.CurrentIndex = _oldIndex; } // Restore the old base offset _baseOffset = oldBaseOffset; }