Пример #1
0
 public ToolLink()
 {
     _notAvailableReasonValue = Lazier.Create(() => {
         var list = NotAvailableReasonFunc?.Invoke().ToList();
         return(list?.Count > 1 ? list.Select(x => "• " + x).JoinToString(";\n").ToSentence() : list?.Count > 0 ? list[0] : null);
     });
 }
Пример #2
0
        public WrapperContentObject(AcCommonObject acObject, string contentDirectory)
        {
            _contentDirectory = contentDirectory;
            CanBePacked       = acObject.CanBePacked();

            AcObject = acObject;
            Version  = ContentVersion = (acObject as IAcObjectVersionInformation)?.Version;

            AcObject.SubscribeWeak((sender, args) => {
                switch (args.PropertyName)
                {
                case nameof(AcCommonObject.DisplayName):
                    UpdateDisplayName();
                    break;

                case nameof(IAcObjectVersionInformation.Version):
                    var updated = (acObject as IAcObjectVersionInformation)?.Version;
                    if (Version == ContentVersion)
                    {
                        Version = updated;
                    }

                    ContentVersion = updated;
                    break;
                }
            });

            UpdateDisplayName();
            _sizeLazy          = Lazier.Create(GetSize);
            _fileIsMissingLazy = Lazier.Create(() => ShareMode == ShareMode.Directly && Filename != null && !File.Exists(Filename));
        }
Пример #3
0
 public ImageInformation(ImageViewerImageCallback imageCallback, ImageViewerDetailsCallback detailsCallback, int position)
 {
     _imageCallback   = imageCallback;
     _detailsCallback = detailsCallback;
     _position        = position;
     _details         = Lazier.Create(GetDetails);
 }
Пример #4
0
 public Emoji([NotNull] string id, [NotNull] IEmojiLoader loader, [NotNull] IEmojiInformationProvider informationProvider)
 {
     _id         = id;
     _loader     = loader;
     Image       = Lazier.Create(LoadImageSource);
     Information = informationProvider.GetInformation(_id);
 }
Пример #5
0
        static PatchHelper()
        {
            _installed = Lazier.Create(() => {
                var installedLogFilename = GetInstalledLog();
                if (!File.Exists(installedLogFilename))
                {
                    return(Tuple.Create <string, string>(null, null));
                }

                string version = null, build = null;
                foreach (var line in File.ReadAllLines(installedLogFilename).Select(x => x.Trim()).Where(x => !x.StartsWith(@"#")))
                {
                    var keyValue = line.Split(new[] { ':' }, 2, StringSplitOptions.None);
                    if (keyValue.Length != 2)
                    {
                        continue;
                    }
                    switch (keyValue[0].Trim())
                    {
                    case "version":
                        version = keyValue[1].Trim();
                        break;

                    case "build":
                        build = keyValue[1].Trim();
                        break;
                    }
                }

                return(Tuple.Create(version, build));
            });
        }
Пример #6
0
 public SettingValue(string name, string value, ZipArchiveEntry entry, double performanceHitMs, bool isActive)
 {
     DisplayName = name.ToSentenceMember();
     Data        = Lazier.Create(() => entry.Open().ReadAsBytesAndDispose());
     Value       = value;
     PerformanceHitPercentage = performanceHitMs / 12 * 100;
     IsActive = isActive;
 }
Пример #7
0
        public BuiltInPresetEntry([NotNull] string baseDirectory, [NotNull] string filename, [NotNull] string extension, byte[] data)
        {
            _extension      = extension;
            _baseDirectory  = baseDirectory;
            _data           = data;
            VirtualFilename = filename;

            _displayName = Lazier.Create(GetDisplayName);
        }
Пример #8
0
        private void LoadDriverModel()
        {
            if (_driver != null)
            {
                return;
            }

            var driverDescription = _carData.GetDriverDescription();

            if (driverDescription == null || !File.Exists(_driverModelFilename))
            {
                return;
            }

            var driver = new Kn5RenderableDriver(Kn5.FromFile(_driverModelFilename), Matrix.Translation(driverDescription.Offset),
                                                 _currentSkin == null ? null : Path.Combine(_skinsDirectory, _currentSkin),
                                                 AsyncTexturesLoading, _asyncOverrideTexturesLoading, _converter)
            {
                LiveReload     = LiveReload,
                MagickOverride = MagickOverride
            };

            _driver = driver;

            if (File.Exists(_driverHierarchyFilename))
            {
                driver.AlignNodes(Knh.FromFile(_driverHierarchyFilename));
            }

            _driverSteerAnimator = Lazier.Create(() => {
                var animator = CreateAnimator(RootDirectory, driverDescription.SteerAnimation,
                                              clampEnabled: false, skipFixed: false);
                if (animator == null)
                {
                    return(null);
                }

                animator.Reset += OnSteerAnimatorReset;
                return(animator);
            });
            _driverSteerLock = driverDescription.SteerAnimationLock;

            driver.LocalMatrix = RootObject.LocalMatrix;
            Add(driver);
            ObjectsChanged?.Invoke(this, EventArgs.Empty);

            if (_steerDeg != 0 || OptionFixKnh)
            {
                UpdateDriverSteerAnimation(GetSteerOffset());
            }

            if (DebugMode)
            {
                driver.DebugMode = true;
            }
        }
Пример #9
0
        public SavedPresetEntry(string baseDirectory, string extension, string filename)
        {
            _baseDirectory        = baseDirectory;
            _displayBaseDirectory = baseDirectory;
            _extension            = extension;
            VirtualFilename       = filename;

            _displayName      = Lazier.Create(GetDisplayName);
            _shortDisplayName = Lazier.Create(GetShortDisplayName);
        }
Пример #10
0
        public ServerEntry([NotNull] ServerInformation information)
        {
            if (information == null)
            {
                throw new ArgumentNullException(nameof(information));
            }
            _sortingName = Lazier.Create(() => GetSortingName(DisplayName));

            Id       = information.Id;
            Ip       = information.Ip;
            PortHttp = information.PortHttp;
            Ping     = null;
            UpdateValuesAsync(information, true).Ignore();
        }
Пример #11
0
        public async Task TestAsync()
        {
            var i = 0;
            var l = Lazier.Create(async() => {
                var v = ++i;
                await Task.Delay(25);
                return(v);
            }, -1);

            Assert.IsFalse(l.IsSet);
            Assert.AreEqual(-1, l.Value);
            Assert.AreEqual(1, i);
            Assert.IsFalse(l.IsSet);
            await Task.Delay(1);

            Assert.AreEqual(1, i);
            Assert.AreEqual(-1, l.Value);
            Assert.IsFalse(l.IsSet);
            await Task.Delay(50);

            Assert.AreEqual(1, l.Value);
            Assert.IsTrue(l.IsSet);
            Assert.AreEqual(1, l.Value);
            l.Reset();



            Assert.IsFalse(l.IsSet);
            Assert.AreEqual(-1, l.Value);
            Assert.AreEqual(2, i);
            await Task.Delay(50);

            Assert.AreEqual(2, l.Value);
            Assert.IsTrue(l.IsSet);
            Assert.AreEqual(2, l.Value);
            l.Reset();


            Assert.AreEqual(-1, l.Value);
            Assert.AreEqual(3, i);
            await Task.Delay(15);

            l.Reset();
            Assert.AreEqual(-1, l.Value);
            Assert.AreEqual(4, i);
            await Task.Delay(50);

            Assert.AreEqual(4, l.Value);
        }
Пример #12
0
        static AcShadowsPatcher()
        {
            SupportedVersions = Lazier.Create(() => {
                var x86   = _data?.For32BitVersion?.Where(x => x.Value.Original != null).Select(x => x.Key).JoinToReadableString();
                var x64   = _data?.For64BitVersion?.Where(x => x.Value.Original != null).Select(x => x.Key).JoinToReadableString();
                var items = new[] {
                    string.IsNullOrWhiteSpace(x86) ? null : "32-bit: " + x86,
                    string.IsNullOrWhiteSpace(x64) ? null : "64-bit: " + x64,
                }.NonNull().ToArray();
                return(items.Length == 0 ? "Definitions are missing" : items.JoinToString(Environment.NewLine));
            });

            ReloadData(true);
            FilesStorage.Instance.Watcher(ContentCategory.Miscellaneous).Update += (s, a) => ReloadData(false);
        }
Пример #13
0
        private DataProvider()
        {
            FilesStorage.Instance.Watcher(ContentCategory.Miscellaneous).Update += OnUpdate;

            _nameNationalities = Lazier.Create(() => NationalitiesAndNames.SelectMany(
                                                   x => from y in x.Value select new NameNationality {
                Name = y, Nationality = x.Key
            }).ToList());

            _countryToIds      = Lazier.Create <IReadOnlyDictionary <string, string> >(() => CountryByIds.ToDictionary(x => x.Value, x => x.Key));
            _countryToKunosIds = Lazier.Create <IReadOnlyDictionary <string, string> >(() => CountryByKunosIds.ToDictionary(x => x.Value, x => x.Key));

            _carYears      = Lazier.Create <IReadOnlyDictionary <string, int> >(() => Years.GetValueOrDefault("cars") ?? new Dictionary <string, int>());
            _trackYears    = Lazier.Create <IReadOnlyDictionary <string, int> >(() => Years.GetValueOrDefault("tracks") ?? new Dictionary <string, int>());
            _showroomYears = Lazier.Create <IReadOnlyDictionary <string, int> >(() => Years.GetValueOrDefault("showrooms") ?? new Dictionary <string, int>());
        }
Пример #14
0
        public void TestBasic()
        {
            var i = 0;
            var l = Lazier.Create(() => ++ i);

            Assert.IsFalse(l.IsSet);
            Assert.AreEqual(1, l.Value);
            Assert.IsTrue(l.IsSet);
            Assert.AreEqual(1, l.Value);
            l.Reset();
            Assert.IsFalse(l.IsSet);
            Assert.AreEqual(2, l.Value);
            Assert.IsTrue(l.IsSet);
            Assert.AreEqual(2, l.Value);
            l.Reset();
            Assert.AreEqual(3, l.Value);
        }
Пример #15
0
            public WeatherProceduralContext(IniFile raceIni, string weatherLocation)
            {
                _raceIni           = raceIni;
                RaceIni            = new LuaIniFile(raceIni);
                TrackId            = $@"{raceIni["RACE"].GetNonEmpty("TRACK")}/{raceIni["RACE"].GetNonEmpty("CONFIG_TRACK")}".TrimEnd('/');
                _weatherIni        = Lazier.Create(() => new LuaIniFile(Path.Combine(weatherLocation, "weather.ini")));
                _colorCurvesIni    = Lazier.Create(() => new LuaIniFile(Path.Combine(weatherLocation, "colorCurves.ini")));
                _weatherFilterIni  = Lazier.Create(() => new LuaIniFile(Path.Combine(weatherLocation, "filter.ini")));
                _tyreSmokeIni      = Lazier.Create(() => new LuaIniFile(Path.Combine(weatherLocation, "tyre_smoke.ini")));
                _tyreSmokeGrassIni = Lazier.Create(() => new LuaIniFile(Path.Combine(weatherLocation, "tyre_smoke_grass.ini")));
                _userFilterIni     = Lazier.Create(() => new LuaIniFile(PpFiltersManager.Instance.GetByAcId(AcSettingsHolder.Video.PostProcessingFilter)?.Location));

                // BUG: USE BACKUPED VALUES IF ANY INSTEAD!
                _trackLightingIni = Lazier.Create(() => new LuaIniFile(Path.Combine(Track.DataDirectory, "lighting.ini")));

                _track            = Lazier.Create(() => TracksManager.Instance.GetLayoutById(TrackId));
                _activeTrackSkins = Lazier.Create(() => Track.MainTrackObject.EnabledOnlySkins.Where(x => x.IsActive).ToList());
            }
Пример #16
0
        public ServerEntry([NotNull] ServerInformation information)
        {
            if (information == null)
            {
                throw new ArgumentNullException(nameof(information));
            }
            _sortingName = Lazier.Create(() => GetSortingName(DisplayName));

            Id       = information.Id;
            Ip       = information.Ip;
            PortHttp = information.PortHttp;
            Ping     = null;

            PrepareErrorsList();
            var status = UpdateValues(information, true, true);

            Status = status == ServerStatus.MissingContent ? ServerStatus.Unloaded : status ?? ServerStatus.Unloaded;
            UpdateErrorsList();
        }
Пример #17
0
        protected static IEnumerable <IKn5RenderableObject> Flatten(Kn5 kn5, IEnumerable <IRenderableObject> root, [CanBeNull] string textureName,
                                                                    [CanBeNull] string objectPath)
        {
            var split = Lazier.Create(() => objectPath?.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries));

            bool TestObjectPath(IKn5RenderableObject obj)
            {
                var s = split.Value;

                if (s == null || s.Length < 1)
                {
                    return(true);
                }
                if (s[s.Length - 1] != obj.OriginalNode.Name)
                {
                    return(false);
                }
                return(kn5.GetObjectPath(obj.OriginalNode) == objectPath);
            }

            return(Flatten(root, x => {
                if (!(x is IKn5RenderableObject k))
                {
                    return true;
                }
                if (!TestObjectPath(k))
                {
                    return false;
                }
                if (textureName == null)
                {
                    return true;
                }
                var material = kn5.GetMaterial(k.OriginalNode.MaterialId);
                return material != null && material.TextureMappings.Where(y => y.Name != "txDetail" && y.Name != "txNormalDetail")
                .Any(m => m.Texture == textureName);
            }));
Пример #18
0
        private PaintShopFontSource([NotNull] string familyName, [CanBeNull] string filename, [CanBeNull] byte[] data)
        {
            FamilyName      = familyName;
            _filenameLazier = Lazier.Create(() => {
                if (filename != null)
                {
                    return(filename);
                }
                if (data == null)
                {
                    return(null);
                }

                string f;
                using (var sha1 = SHA1.Create()) {
                    f = Path.Combine(Path.GetTempPath(), "font-" + sha1.ComputeHash(data).ToHexString().ToLowerInvariant() + ".ttf");
                }
                if (!File.Exists(f))
                {
                    File.WriteAllBytes(f, data);
                }
                return(f);
            });
        }
Пример #19
0
        private void IterateString(string text, Vector2 position, float angle, bool draw, float scale, Color4 color, CoordinateType coordinateType,
                                   out StringMetrics metrics)
        {
            metrics = new StringMetrics();
            float scalY = coordinateType == CoordinateType.SNorm ? -1 : 1;

            var visualText = NBidi.NBidi.LogicalToVisual(text);
            var codePoints = Helpers.ConvertToCodePointArray(visualText);

            float sine, cosine;

            if (angle != 0f)
            {
                sine   = (float)Math.Sin(angle);
                cosine = (float)Math.Cos(angle);
            }
            else
            {
                sine = cosine = 0f;
            }

            var x = 0f;
            var y = Lazier.Create(() => Math.Abs(GetCharDescription('M').CharSize.Y *scale *scalY));

            for (var i = 0; i < codePoints.Length; i++)
            {
                var c           = codePoints[i];
                var charDesc    = GetCharDescription(c);
                var charMetrics = charDesc.ToStringMetrics(position, scale, scale * scalY);
                metrics.Merge(charMetrics);

                if (c != '\r' && c != '\n')
                {
                    if (draw)
                    {
                        var h = charMetrics.FullRectSize.Y;
                        if (h != 0 && charMetrics.FullRectSize.X != 0)
                        {
                            var fix = new Vector2(-charMetrics.OverhangLeft, -scalY * charMetrics.OverhangTop);
                            if (angle != 0f)
                            {
                                fix = SpriteRenderer.Rotate(fix, sine, cosine);
                            }

                            Sprite.Draw(charDesc.TableDescription.Srv, position + fix, charMetrics.FullRectSize,
                                        Vector2.Zero, sine, cosine, charDesc.TexCoordsStart, charDesc.TexCoordsSize, color, coordinateType);
                        }
                    }
                }

                var delta = new Vector2(charMetrics.Size.X + KerningAdjustment, 0f);

                switch (c)
                {
                case '\n':
                    delta.Y += y.Value;
                    goto case '\r';

                case '\r':
                    delta.X = -x;
                    x       = 0f;
                    break;

                default:
                    x += delta.X;
                    break;
                }

                if (angle != 0f)
                {
                    delta = SpriteRenderer.Rotate(delta, sine, cosine);
                }

                position += delta;
            }
        }
Пример #20
0
 public WeatherObject(IFileAcManager manager, string id, bool enabled)
     : base(manager, id, enabled)
 {
     _temperatureDiapasonLazier = Lazier.Create(() => TemperatureDiapason == null ? null : Diapason.CreateDouble(TemperatureDiapason));
     _timeDiapasonLazier        = Lazier.Create(() => TimeDiapason == null ? null : Diapason.CreateTime(TimeDiapason));
 }
 private void InitializeAccumulationDof()
 {
     _lazyAccumulationDofPoissonDiskSamples   = Lazier.Create(() => Reorder(UniformPoissonDiskSampler.SampleCircle(_accumulationDofIterations)));
     _lazyAccumulationDofPoissonSquareSamples = Lazier.Create(() => UniformPoissonDiskSampler.SampleSquare(_accumulationDofIterations, false).ToArray());
 }
Пример #22
0
 public BlacklistItem(string guid)
 {
     Guid     = guid;
     _knownAs = Lazier.Create(() => ServerGuidsStorage.GetAssociatedUserName(Guid));
 }
Пример #23
0
 public ColorReference(Func <Color?> callback)
 {
     _value = Lazier.Create(callback);
 }