Пример #1
0
        public void OnEventAcquired(object sender, ParserEventArgs args)
        {
            try
            {
                //Update property window anyway
                PropertyGridViewModel.Clear();
                DataViewModel?.Clear();

                if (args == null)
                {
                    throw new NullReferenceException("Invalid arguments passed");
                }

                PropertyGridViewModel.AddData(args.TreeNode?.Properties);

                var argsType = args.ArgsType;

                if ((argsType & MessageType.ProcessAll) != 0)
                {
                    DataViewModel = MarkupManager.Resolve(args.TreeNode?.Markup) ?? new DataGridViewModel();
                    DataViewModel.ProcessNodeData(args.TreeNode);
                }

                DataViewModel?.Refresh();
                PropertyGridViewModel.Refresh();
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
            }
        }
Пример #2
0
        public override void OnLoadData()
        {
            Logger.LogDebug($"{nameof(Serializer)}.{nameof(OnLoadData)}");

            if (serializableDataManager.LoadData(Id) is byte[] data)
            {
                try
                {
                    var sw = Stopwatch.StartNew();

                    var decompress = Decompress(data);
#if DEBUG
                    Logger.LogDebug(decompress);
#endif
                    var config = Parse(decompress);
                    MarkupManager.FromXml(config);

                    sw.Stop();
                    Logger.LogDebug($"Data was loaded in {sw.ElapsedMilliseconds}ms; Size = {data.Length} bytes");
                }
                catch (Exception error)
                {
                    Logger.LogError(() => "Could load data", error);
                }
            }
            else
            {
                Logger.LogDebug($"Saved data not founded");
            }
        }
Пример #3
0
        public static bool OnImportData(string file)
        {
            Logger.LogDebug($"{nameof(Serializer)}.{nameof(OnImportData)}");

            try
            {
                using (var fileStream = File.OpenRead(file))
                    using (var reader = new StreamReader(fileStream))
                    {
                        var xml    = reader.ReadToEnd();
                        var config = Parse(xml);

                        MarkupManager.FromXml(config);

                        Logger.LogDebug($"Data was imported");

                        return(true);
                    }
            }
            catch (Exception error)
            {
                Logger.LogError(() => "Could import data", error);
                return(false);
            }
        }
Пример #4
0
        public override void OnSaveData()
        {
            Logger.LogDebug($"{nameof(Serializer)}.{nameof(OnSaveData)}");

            string xml = string.Empty;

            try
            {
                var sw = Stopwatch.StartNew();

                var config = MarkupManager.ToXml();
                xml = config.ToString(SaveOptions.DisableFormatting);
#if DEBUG
                Logger.LogDebug(xml);
#endif
                var compress = Compress(xml);
                serializableDataManager.SaveData(Id, compress);

                sw.Stop();
                Logger.LogDebug($"Data saved in {sw.ElapsedMilliseconds}ms; Size = {compress.Length} bytes");
            }
            catch (Exception error)
            {
                Logger.LogError(() => "Save data failed", error);
                SaveSettingDump(xml, out _);
                throw;
            }
        }
Пример #5
0
        public override void Paste(InstanceID targetInstanceID, object record, Dictionary <InstanceID, InstanceID> sourceMap)
        {
            if (targetInstanceID.Type == InstanceType.NetNode)
            {
                ushort nodeID = targetInstanceID.NetNode;
                var    map    = new Dictionary <ObjectId, ObjectId>();
                foreach (var source in sourceMap)
                {
                    if (source.Key.Type == InstanceType.NetSegment && source.Value.Type == InstanceType.NetSegment)
                    {
                        map.Add(new ObjectId()
                        {
                            Segment = source.Key.NetSegment
                        }, new ObjectId()
                        {
                            Segment = source.Value.NetSegment
                        });
                    }
                }

                if (record is XElement config)
                {
                    var markup = MarkupManager.Get(nodeID);
                    markup.FromXml(Mod.Version, config, map);
                }
            }
        }
Пример #6
0
        public override void OnCreated(ILoading loading)
        {
            Logger.LogDebug($"{nameof(LoadingExtension)}.{nameof(OnCreated)}");
            base.OnCreated(loading);

            MarkupManager.Clear();
            TemplateManager.Clear();
        }
Пример #7
0
        protected override void OnLoad()
        {
            MarkupManager.UpdateAll();
            DataManager.Reload();

            if (MarkupManager.HasErrors)
            {
                var messageBox = MessageBox.Show <ErrorSupportMessageBox>();
                messageBox.Init <Mod>();
                messageBox.MessageText = MarkupManager.Errors > 0 ? string.Format(Localize.Mod_LoadFailed, MarkupManager.Errors) : Localize.Mod_LoadFailedAll;
            }

            base.OnLoad();
        }
Пример #8
0
        public override void OnAssetSaved(string name, object asset, out Dictionary <string, byte[]> userData)
        {
            userData = new Dictionary <string, byte[]>();
            if (asset is not BuildingInfo prefab || !prefab.m_paths.Any())
            {
                return;
            }

            Mod.Logger.Debug($"Start save prefab data \"{prefab.name}\"");
            try
            {
                var config = Loader.GetString(MarkupManager.ToXml());
                var data   = Loader.Compress(config);

                userData[DataId] = data;

                var instance = Singleton <NetManager> .instance;

                var segmentsId = new List <ushort>();
                for (ushort i = 0; i < NetManager.MAX_SEGMENT_COUNT; i += 1)
                {
                    if ((instance.m_segments.m_buffer[i].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.Created)
                    {
                        segmentsId.Add(i);
                    }
                }

                var map = new byte[sizeof(ushort) * 3 * segmentsId.Count];

                for (var i = 0; i < segmentsId.Count; i += 1)
                {
                    var segmentId = segmentsId[i];
                    var segment   = instance.m_segments.m_buffer[segmentId];
                    GetBytes(segmentId, out map[i * 6], out map[i * 6 + 1]);
                    GetBytes(segment.m_startNode, out map[i * 6 + 2], out map[i * 6 + 3]);
                    GetBytes(segment.m_endNode, out map[i * 6 + 4], out map[i * 6 + 5]);
                }

                userData[MapId] = map;

                Mod.Logger.Debug($"Prefab data was saved; Size = {data.Length} bytes");
            }
            catch (Exception error)
            {
                Mod.Logger.Error("Could not save prefab data", error);
            }
        }
Пример #9
0
        public static bool OnDumpData(out string path)
        {
            Logger.LogDebug($"{nameof(Serializer)}.{nameof(OnDumpData)}");

            try
            {
                var config = MarkupManager.ToXml();
                var xml    = config.ToString(SaveOptions.DisableFormatting);

                return(SaveSettingDump(xml, out path));
            }
            catch (Exception error)
            {
                Logger.LogError(() => "Save dump failed", error);

                path = string.Empty;
                return(false);
            }
        }
Пример #10
0
    IEnumerator BuildText()
    {
        int runsThisFrame = 0;

        string[] textArray = hasMarkup ? MarkupManager.SplitByTag(targetText) : new string[1] {
            targetText
        };

        // If this is additive text, make sure we include the previous text.

        _currentText = previousText;

        // We need a storage variable to separate out the nested text.
        string nestedText = ""; // aka curText

        // Build the text by moving through each part
        for (int i = 0; i < textArray.Length; i++)
        {
            string section = textArray[i];

            // Tags will always be odd-indexed.  Even if there are two in a row, there will be an empty array between them.
            bool isOdd = i % 2 == 1;

            if (isOdd && hasMarkup)
            {
                // store the current text into something that can be referenced as a restart point as tagged sections of text get added or removed.

                nestedText = _currentText;

                NESTED_TEXT childNode = new NESTED_TEXT($"<{section}>", textArray, i);
                while (!childNode.isDone)
                {
                    //during each loop we need to call the next step in the markup process
                    // First set a boolean to indicate if a step was taken
                    bool stepped = childNode.Step();

                    _currentText = nestedText + childNode.displayText;

                    // Only yield if a step was taken in building the string
                    if (stepped)
                    {
                        runsThisFrame++;
                        int maxRunsPerFrame = skip ? 5 : charactersPerFrame; // Handles fast forwarding // Move the variable declaration up?

                        if (runsThisFrame == maxRunsPerFrame)
                        {
                            runsThisFrame = 0;
                            yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * renderSpeed));
                        }
                    }
                }
                i = childNode.arrayProgress + 1;
            }
            else // Not processing markup
            {
                for (int j = 0; j < section.Length; j++)
                {
                    _currentText += section[j];
                    runsThisFrame++;
                    int maxRunsPerFrame = skip ? 5 : charactersPerFrame; // Handles fast forwarding // Move the variable declaration up?

                    if (runsThisFrame == maxRunsPerFrame)
                    {
                        runsThisFrame = 0;
                        yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * renderSpeed));
                    }
                }
            }
        }

        // Signal the end of the build process
        buildProcess = null;
    }
Пример #11
0
        public void TestCalculateMarkupForMinimumFareDifference()
        {
            System.Collections.Generic.List <Itinerary> disountList = new System.Collections.Generic.List <Itinerary>();

            Itinerary published = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 1,

                TotalLayoverTime = new TimeSpan(4, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 100,

                MarkupInUSD = 0
            };

            Itinerary discounted1 = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 2,

                TotalLayoverTime = new TimeSpan(0, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 60,

                MarkupInUSD = 0
            };

            disountList.Add(discounted1);
            Itinerary discounted2 = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 3,

                TotalLayoverTime = new TimeSpan(0, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 60,

                MarkupInUSD = 0
            };

            disountList.Add(discounted2);

            disountList = new MarkupManager().CalculateMarkup(published, disountList);

            Assert.AreEqual(15, disountList[0].TotalFareInUSD - disountList[1].TotalFareInUSD);
        }
Пример #12
0
        public void TestCalculateMarkupForMinimumFareDifference()
        {
            System.Collections.Generic.List<Itinerary> disountList = new System.Collections.Generic.List<Itinerary>();

            Itinerary published = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 1,

                TotalLayoverTime = new TimeSpan(4, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 100,

                MarkupInUSD = 0

            };

            Itinerary discounted1 = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 2,

                TotalLayoverTime = new TimeSpan(0, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 60,

                MarkupInUSD = 0

            };

            disountList.Add(discounted1);
            Itinerary discounted2 = new Itinerary()
            {
                OriginAirportCode = "001",

                DestinationAirportCode = "005",

                FlightTime = new TimeSpan(4, 0, 0),

                NumberOfStops = 3,

                TotalLayoverTime = new TimeSpan(0, 0, 0),

                Airline = "Indigo",

                UtcDepartureTime = DateTime.UtcNow,

                UtcArrivalTime = DateTime.UtcNow,

                BaseFareInUSD = 60,

                MarkupInUSD = 0

            };

            disountList.Add(discounted2);

            disountList = new MarkupManager().CalculateMarkup(published, disountList);

            Assert.AreEqual(15, disountList[0].TotalFareInUSD - disountList[1].TotalFareInUSD);
        }