Esempio n. 1
0
        private void Track(string key, PropertyTypes type, IReloadable target)
        {
            Debug.Assert(map.ContainsKey(key), $"Missing property '{key}'.");

            // This is useful for properties that should never be iterated during gameplay (or where live modification
            // would be too cumbersome or error-prone).
            if (target == null)
            {
                return;
            }

            var matchedProperty = tracker.Keys.FirstOrDefault(p => p.Key == key);

            // This means that the given target is the first to track the given key.
            if (matchedProperty.Key == null)
            {
                var list = new List <IReloadable>();
                list.Add(target);

                tracker.Add((key, type), list);
            }
            else
            {
                Debug.Assert(type == matchedProperty.Type, $"Type conflict for property '{key}' (was previously " +
                             $"retrieved as {matchedProperty.Type}, but is now being retrieved as {type}).");

                var targets = tracker[matchedProperty];

                if (!targets.Contains(target))
                {
                    targets.Add(target);
                }
            }
        }
Esempio n. 2
0
 public FilePreview(IReloadable owner, FileData fileData)
 {
     mFileData = fileData;
     InitializeComponent();
     textBox.Text = mFileData.FlatFileData;
     mOwner       = owner;
 }
Esempio n. 3
0
        public static PropertyAccessor Access(IReloadable target)
        {
            target.Reload(accessor);

            // Returning the accessor directly allows targets to also retrieve any non-reloadable values.
            return(accessor);
        }
Esempio n. 4
0
        public FilePreview(IReloadable owner, FileData fileData)
        {
            mFileData = fileData;
            InitializeComponent();
            textBox.Text = mFileData.FlatFileData;
            mOwner       = owner;

            gotoLineDialog                = new GoTo(textBox);
            findReplaceDialog             = new FindReplace(textBox);
            findReplaceDialog.KeyPressed += findReplaceDialog_KeyPressed;

            this.configureScintilla();

            localizeFile.Visible = textBox.Lexer == ScintillaNET.Lexer.Json;
            bool hasMixins = false;

            if ((mFileData as JsonFileData) != null)
            {
                if ((mFileData as JsonFileData).Json != null)
                {
                    hasMixins = (mFileData as JsonFileData).Json.SelectToken("mixins") != null;
                }
            }

            previewMixinsButton.Visible = (textBox.Lexer == ScintillaNET.Lexer.Json) && hasMixins;
        }
Esempio n. 5
0
        private void Validate(string key, PropertyTypes type, IReloadable target, bool shouldTrack)
        {
            Debug.Assert(map.ContainsKey(key), $"Missing property '{key}'.");

            // This is useful for properties that should never be iterated during gameplay (or where live modification
            // would be too cumbersome or error-prone).
            if (target == null || !shouldTrack)
            {
                return;
            }

            var matchedProperty = tracker.Keys.FirstOrDefault(p => p.Key == key);

            if (matchedProperty == null)
            {
                var list = new List <IReloadable>();
                list.Add(target);

                tracker.Add(new Property(key, type), list);
            }
            else
            {
                Debug.Assert(type == matchedProperty.Type, $"Type conflict for property '{key}' (was previously " +
                             $"retrieved as {matchedProperty.Type}, but is now {type}).");

                var targets = tracker[matchedProperty];

                // It's fine for the same object accesses the same property multiple times (this most commonly occurs
                // when a property is modified, triggering a reload).
                if (!targets.Contains(target))
                {
                    targets.Add(target);
                }
            }
        }
Esempio n. 6
0
        public bool TryGetUInt(string key, PropertyConstraints constraint, out uint result, out string message,
                               IReloadable target = null)
        {
            Track(key, PropertyTypes.UnsignedInteger, target);

            if (!uint.TryParse(map[key], out result))
            {
                message = Format(key, PropertyTypes.UnsignedInteger);

                return(true);
            }

            // The signed integer validator can be reused here. Using a constraint of NonNegative doesn't really make
            // sense for an unsigned integer (since that's always true), but it's also not an error.
            if (Validate((int)result, constraint))
            {
                message = null;

                return(true);
            }

            message = Format(key, constraint);

            return(false);
        }
Esempio n. 7
0
 void Awake()
 {
     fireMech    = GetComponent <FireMechanism>();
     ammoSys     = GetComponent <AmmoSystem>();
     drawRelease = GetComponent <DrawReleaseScript>();
     reloadable  = GetComponent <IReloadable>();
 }
Esempio n. 8
0
 public static async Task ReloadData()
 {
     await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
     {
         IReloadable p => Task.Run(p.ReloadData),
         IAsyncReloadable p => p.ReloadDataAsync(),
         _ => Task.CompletedTask,
     }).ToArray());
Esempio n. 9
0
 private void HandleReloadableWeapon(IWeapon baseWeapon)
 {
     if (baseWeapon is IReloadable)
     {
         _reloadableWeapon = baseWeapon as IReloadable;
         _reloadableWeapon.ReloadCallback.AddListener(Reload);
     }
 }
        public static Job MakeReloadJob(IReloadable comp, Thing ammo)
        {
            var job = JobMaker.MakeJob(ReloadingDefOf.ReloadFromInventory, comp.Thing);

            job.targetB = ammo;
            job.count   = Math.Min(ammo.stackCount,
                                   comp.ItemsPerShot * (comp.MaxShots - comp.ShotsRemaining));
            return(job);
        }
        public FilePreview(IReloadable owner, FileData fileData)
        {
            mFileData = fileData;
            InitializeComponent();
            textBox.Text = mFileData.FlatFileData;
            mOwner = owner;

            this.configureScintilla();
        }
Esempio n. 12
0
        public static void subscribeForChange(IReloadable reloadableTarget)
        {
            if (ServiceConfiguration.ReloadableTargets == null)
            {
                ServiceConfiguration.ReloadableTargets = new List <IReloadable>();
            }

            ServiceConfiguration.ReloadableTargets.Add(reloadableTarget);
        }
Esempio n. 13
0
        public void ListenForChange(IReloadable newListener)
        {
            if (ChangeListeners == null)
            {
                ChangeListeners = new List <IReloadable>();
            }

            ChangeListeners.Add(newListener);
        }
Esempio n. 14
0
 void Awake()
 {
     fireMech    = GetComponent <FireMechanism>();
     ammoSys     = GetComponent <AmmoSystem>();
     recoil      = GetComponent <RecoilBase>();
     scopeStatus = GetComponent <IScopeStatus>();
     scope       = GetComponent <ScopeBase>();
     reloadable  = GetComponent <IReloadable>();
 }
Esempio n. 15
0
        public static Job MakeReloadJob(IReloadable comp, List <Thing> ammo)
        {
            var job = JobMaker.MakeJob(ReloadingDefOf.BetterReload, comp.Thing);

            job.targetQueueB = ammo.Select(t => new LocalTargetInfo(t)).ToList();
            job.count        = Math.Min(ammo.Sum(t => t.stackCount),
                                        comp.ItemsPerShot * (comp.MaxShots - comp.ShotsRemaining));
            return(job);
        }
Esempio n. 16
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        /// <param name="table">公共数据容器</param>
        /// <returns>是否刷新成功</returns>
        public override bool ReloadData(System.Collections.Hashtable table)
        {
            if (this.data != null)
            {
                if (this.data is IReloadable)
                {
                    IReloadable obj         = this.Data as IReloadable;
                    string      forceReload = table["forceReload"] as string;

                    if (forceReload == null || forceReload == "0") // 检查是否需要强制刷新
                    {
                        obj.Reload();
                        this.Text = obj.ToString();

                        if (obj.RequestEdit()) // 检查是否需要重新编辑
                        {
                            string requestReloadID = table["requestReloadID"] as string;

                            if (string.IsNullOrEmpty(requestReloadID))
                            {
                                requestReloadID = this.id.ToString();
                            }
                            else
                            {
                                requestReloadID += string.Format(",{0}", this.id.ToString());
                            }

                            table["requestReloadID"] = requestReloadID;
                        }
                    }
                    else
                    {
                        obj.ForceReload();
                        this.Text = obj.ToString();
                    }
                }
                else if (dataType == "AILine") // 连接线的显示需要单独刷一下
                {
                    string displayText = this.data as string;
                    int    index       = displayText.IndexOf(":");

                    if (index != -1)
                    {
                        this.text = displayText.Substring(index + 1);
                    }
                }
            }

            // 刷新Tip文本
            if (this.data is IFullTextConvertable)
            {
                this.TooltipText = (this.data as IFullTextConvertable).ToFullText();
            }

            return(true);
        }
Esempio n. 17
0
        public static List <Thing> FindAmmo(Pawn pawn, IntVec3 root, IReloadable comp)
        {
            if (comp == null)
            {
                return(null);
            }
            var desired = new IntRange(comp.ItemsPerShot,
                                       comp.ItemsPerShot * (comp.MaxShots - comp.ShotsRemaining));

            return(RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, root, desired, comp.CanReloadFrom));
        }
Esempio n. 18
0
        public Color GetColor(string key, IReloadable target = null, bool shouldTrack = true)
        {
            Validate(key, PropertyTypes.Color, target, shouldTrack);

            if (!Color.TryParse(map[key], out var result))
            {
                Debug.Fail($"Property '{key}={result}' is not a valid color.");
            }

            return(result);
        }
Esempio n. 19
0
        public static PropertyAccessor Access(IReloadable target = null)
        {
            if (target != null && !target.Reload(accessor, out var message))
            {
                // By triggering a failure here, bad properties will be detected on object creation (rather than only
                // on reload via the terminal).
                Debug.Fail(message);
            }

            return(accessor);
        }
Esempio n. 20
0
        public float GetFloat(string key, IReloadable target = null, bool shouldTrack = true)
        {
            Validate(key, PropertyTypes.Float, target, shouldTrack);

            if (!float.TryParse(map[key], out var result))
            {
                Debug.Fail($"Property '{key}={result}' is not a valid float.");
            }

            return(result);
        }
Esempio n. 21
0
        public bool TryGetFloat(string key, PropertyConstraints constraint, out string message, ref float result,
                                IReloadable target = null)
        {
            if (!TryGetFloat(key, constraint, out var value, out message, target))
            {
                return(false);
            }

            result = value;

            return(true);
        }
    public override TaskStatus OnUpdate()
    {
        IReloadable reloadable = ability as IReloadable;

        if (!reloadable.IsReloading())
        {
            return(TaskStatus.Success);
        }
        else
        {
            return(TaskStatus.Failure);
        }
    }
Esempio n. 23
0
        private bool SetControl(Control control)
        {
            if (_currentControl == control)
            {
                return(false);
            }
            panelPlaceholder.Controls.Clear();
            panelPlaceholder.Controls.Add(control);
            control.Dock    = DockStyle.Fill;
            _currentControl = control as IReloadable;

            Text = control == _authorListControl ? "Список авторов" : "Список книг";
            return(true);
        }
Esempio n. 24
0
        public CacheScheduler(IReloadable reloadableInstance, IReloadConfigProfile profile, CancellationToken token,
                              ILog logger, string cacheName)
        {
            reloadableInstance.ThrowIfNull($"{nameof(CacheScheduler)}.{nameof(reloadableInstance)}");
            profile.ReloadDelay();
            _localCts    = new CancellationTokenSource();
            _combinedCts = CancellationTokenSource.CreateLinkedTokenSource(token, _localCts.Token);
            _token       = _combinedCts.Token;

            _instance   = reloadableInstance;
            _profile    = profile;
            _logger     = logger;
            _cacheName  = cacheName;
            _reloadTask = BeginReloading();
        }
Esempio n. 25
0
        public bool TryGetByte(string key, out byte result, out string message, IReloadable target = null)
        {
            Track(key, PropertyTypes.Byte, target);

            if (!byte.TryParse(map[key], out result))
            {
                message = Format(key, PropertyTypes.Byte);

                return(false);
            }

            // Byte constraints are implied (they must be a positive value between 0 and 255 inclusive).
            message = null;

            return(true);
        }
Esempio n. 26
0
    public void remove(IReloadable listener)
    {
        int id = listener.GetHashCode();

        for (int i = 0, c = reloadables.Length; i < c; ++i)
        {
            if (reloadables[i] == null)
            {
                continue;
            }
            if (id == reloadables[i].GetHashCode())
            {
                reloadables[i] = null;
                break;
            }
        }
    }
Esempio n. 27
0
        public bool TryGetColor(string key, out Color result, out string message, IReloadable target = null)
        {
            Track(key, PropertyTypes.Color, target);

            if (!Color.TryParse(map[key], out result))
            {
                message = Format(key, PropertyTypes.Color);

                return(false);
            }

            // Since colors use bytes, they can't be constrained (the byte conversion would fail if any value is
            // outside the 0-255 range).
            message = null;

            return(true);
        }
Esempio n. 28
0
        public bool TryGetFloats(string[] keys, PropertyConstraints constraint, out Dictionary <string, float> results,
                                 out string message, IReloadable target = null)
        {
            results = new Dictionary <string, float>();

            foreach (var key in keys)
            {
                if (!TryGetFloat(key, constraint, out var result, out message, target))
                {
                    return(false);
                }

                results.Add(key, result);
            }

            message = null;

            return(true);
        }
Esempio n. 29
0
    public void register(IReloadable listener, Vector3 pos)
    {
        bool inserted = false;

        for (int i = 0, c = reloadables.Length; i < c; ++i)
        {
            if (reloadables[i] == null)
            {
                reloadables[i] = listener;
                reloadablesSpawnPos[i].Set(pos.x, pos.y, pos.z);
                inserted = true;
                break;
            }
        }
        if (!inserted)
        {
            Debug.LogError("Reloadables container for listeners is full. Increment size one more unit.");
        }
    }
Esempio n. 30
0
        public bool TryGetBytes(string[] keys, out Dictionary <string, byte> results, out string message,
                                IReloadable target = null)
        {
            results = new Dictionary <string, byte>();

            foreach (var key in keys)
            {
                if (!TryGetByte(key, out var result, out message, target))
                {
                    return(false);
                }

                results.Add(key, result);
            }

            message = null;

            return(true);
        }
Esempio n. 31
0
    public override void Do()
    {
        if (!isReady)
        {
            Debug.Log("Skill is still on cooldown " + timer);
            return;
        }
        Dictionary <HexTile, Tower> towers = TowerManager.Instance.GetTowers();

        //Debug.Log("Reloaded");
        foreach (var tower in towers.Values)
        {
            IReloadable reloadable = tower as IReloadable;
            if (reloadable != null)
            {
                reloadable.Reload();
            }
        }
        isReady = false;
        timer   = cooldown;
    }
Esempio n. 32
0
 public void RegisterControl(IReloadable c)
 {
     this.controllList.Add(c);
 }
Esempio n. 33
0
 public void UnregisterControl(IReloadable c)
 {
     this.controllList.Remove(c);
 }
Esempio n. 34
0
 public static void AddToLevel(IReloadable part)
 {
     levelObjects.Add(part);
     if(part is IRevertable)
     {
         redoStack.Clear();
         undoStack.Push((IRevertable)part);
     }
 }