public static DataPreviewViewModel Create(int offset, TagViewModel tag, IH2Map map)
        {
            var vm = new DataPreviewViewModel(offset, tag);

            // TODO: interned strings isn't prebuilt anymore
            //if(map.InternedStrings.TryGetValue(vm.Short, out var str))
            //{
            //    vm.InternedString = str;
            //}

            if (map.TryGetTag(vm.UInt, out BaseTag t))
            {
                vm.TagName = t.Name;
            }

            var secondaryOffset = map.GetSecondaryOffset(tag.OriginalTag.DataFile, vm.Int);

            vm.FileOffset = tag.OriginalTag.DataFile switch
            {
                DataFile.Local => secondaryOffset.Value.ToString(),
                DataFile.MainMenu => "MM-" + secondaryOffset.Value,
                DataFile.Shared => "MS-" + secondaryOffset.Value,
                DataFile.SinglePlayerShared => "SS-" + secondaryOffset.Value,
            };

            return(vm);
        }
Beispiel #2
0
        public void PopulateChildren(TagViewModel vm, TagTreeEntryViewModel entry)
        {
            if (scene.TryGetTag <BaseTag>(entry.Id, out var tag) == false)
            {
                return;
            }

            var childRefs = GetChildReferences(tag);

            var addedChildren = new HashSet <uint>();
            var childrenVms   = new List <TagTreeEntryViewModel>();


            foreach (var child in childRefs)
            {
                if (addedChildren.Contains(child.Id))
                {
                    continue;
                }

                if (scene.TryGetTag <BaseTag>(child.Id, out var childTag) == false)
                {
                    continue;
                }

                if (childTag == null)
                {
                    if (scene.TagIndex.TryGetValue(child.Id, out var indexEntry) == false)
                    {
                        Console.WriteLine($"Unable to find any tag entry info for ????[{child.Id}]");
                        continue;
                    }

                    Console.WriteLine($"Found null tag for [{indexEntry.Tag}] tag");

                    addedChildren.Add(child.Id);
                    childrenVms.Add(new TagTreeEntryViewModel(childTag));

                    continue;
                }

                string tagLabel = "";

                if (childTag is UnknownTag uk)
                {
                    tagLabel = uk.OriginalLabel + "[?]";
                }
                else
                {
                    if (TagLabels.TryGetValue(childTag.GetType(), out tagLabel) == false)
                    {
                        tagLabel = childTag.GetType().GetCustomAttribute <TagLabelAttribute>().Label.ToString();
                        TagLabels.Add(childTag.GetType(), tagLabel);
                    }
                }


                addedChildren.Add(child.Id);
                childrenVms.Add(new TagTreeEntryViewModel(childTag));
            }

            entry.Children = childrenVms.ToArray();
        }