Exemple #1
0
        public static DivinityLocaleEntry CreateNewLocaleEntry(DivinityLocaleFile fileData, string key = "NewKey", string content = "")
        {
            var rootNode = fileData.Resource.Regions.First().Value;

            var refNode = fileData.Entries.Cast <DivinityLocaleEntry>().Where(f => f.SourceNode != null).FirstOrDefault().SourceNode;

            if (refNode != null)
            {
                var node = new Node();
                node.Parent = rootNode;
                node.Name   = refNode.Name;
                //Log.Here().Activity($"Node name: {node.Name}");
                foreach (var kp in refNode.Attributes)
                {
                    var att = new NodeAttribute(kp.Value.Type);
                    att.Value = new TranslatedString()
                    {
                        Value  = "",
                        Handle = CreateHandle()
                    };
                    node.Attributes.Add(kp.Key, att);
                }

                DivinityLocaleEntry localeEntry = LoadFromNode(node, fileData.Format);
                localeEntry.Key     = key == "NewKey" ? key + (fileData.Entries.Count + 1) : key;
                localeEntry.Content = content;
                return(localeEntry);
            }
            return(null);
        }
Exemple #2
0
        public static DivinityLocaleEntry LoadFromNode(Node node, ResourceFormat resourceFormat, bool generateNewHandle = false)
        {
            if (resourceFormat == ResourceFormat.LSB)
            {
                NodeAttribute keyAtt     = null;
                NodeAttribute contentAtt = null;
                node.Attributes.TryGetValue("UUID", out keyAtt);
                node.Attributes.TryGetValue("Content", out contentAtt);

                DivinityLocaleEntry localeEntry = new DivinityLocaleEntry()
                {
                    SourceNode   = node,
                    KeyAttribute = keyAtt,
                    Locked       = false
                };

                if (contentAtt == null)
                {
                    contentAtt = new NodeAttribute(NodeAttribute.DataType.DT_TranslatedString);
                    if (contentAtt.Value is TranslatedString translatedString)
                    {
                        translatedString.Value       = "";
                        translatedString.Handle      = CreateHandle();
                        localeEntry.TranslatedString = translatedString;
                    }
                    node.Attributes.Add("Content", contentAtt);
                }
                else
                {
                    localeEntry.TranslatedString = contentAtt.Value as TranslatedString;
                }

                if (generateNewHandle)
                {
                    localeEntry.TranslatedString.Handle = CreateHandle();
                }

                return(localeEntry);
            }
            else if (resourceFormat == ResourceFormat.LSJ || resourceFormat == ResourceFormat.LSX)
            {
                DivinityLocaleEntry localeEntry = new DivinityLocaleEntry()
                {
                    SourceNode = node,
                    Locked     = true
                };
                localeEntry.Key = "Dialog Node";

                NodeAttribute contentAtt = null;
                node.Attributes.TryGetValue("TagText", out contentAtt);
                if (contentAtt != null)
                {
                    localeEntry.TranslatedString = contentAtt.Value as TranslatedString;
                }
                return(localeEntry);
            }
            return(null);
        }
Exemple #3
0
        public static bool LoadFromResource(DivinityLocaleFile fileData, Resource resource, ResourceFormat resourceFormat, bool sort = true)
        {
            try
            {
                if (resourceFormat == ResourceFormat.LSB)
                {
                    var rootNode = resource.Regions.First().Value;
                    foreach (var entry in rootNode.Children)
                    {
                        foreach (var node in entry.Value)
                        {
                            DivinityLocaleEntry localeEntry = LoadFromNode(node, resourceFormat);
                            localeEntry.Parent = fileData;
                            fileData.Entries.Add(localeEntry);
                        }
                    }
                }

                if (resourceFormat == ResourceFormat.LSJ || resourceFormat == ResourceFormat.LSX)
                {
                    var rootNode = resource.Regions.First().Value;

                    var stringNodes = new List <Node>();

                    foreach (var nodeList in rootNode.Children)
                    {
                        var nodes = FindTranslatedStringsInNodeList(nodeList);
                        stringNodes.AddRange(nodes);
                    }

                    foreach (var node in stringNodes)
                    {
                        DivinityLocaleEntry localeEntry = LoadFromNode(node, resourceFormat);
                        localeEntry.Parent = fileData;
                        fileData.Entries.Add(localeEntry);
                    }
                }

                if (sort)
                {
                    fileData.Entries = fileData.Entries.OrderBy(e => e.Key).ToList();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Here().Error($"Error loading from resource: {ex.ToString()}");
                return(false);
            }
        }