Ejemplo n.º 1
0
        internal void RegisterPiece(string pieceTable, GameObject prefab)
        {
            PieceTable table = getPieceTable(pieceTable);

            // Error checking
            if (!table)
            {
                Debug.LogError("Failed to register piece, Piece table does not exist: " + pieceTable);
                return;
            }

            if (!prefab)
            {
                Debug.LogError("Failed to register Piece with null prefab");
                return;
            }

            if (!prefab.GetComponent <Piece>())
            {
                Debug.LogError("Failed to register piece, Prefab does not have Piece component: " + prefab.name);
                return;
            }

            // Set layer if not already set
            if (prefab.layer == 0)
            {
                prefab.layer = LayerMask.NameToLayer("piece");
            }

            // Add prefab
            table.m_pieces.Add(prefab);
            Debug.Log("Registered piece: " + prefab.name + " to " + pieceTable);
        }
Ejemplo n.º 2
0
        public void PreviousPointOfEndPoint()
        {
            var table          = PieceTable.ForString("0");
            var pointAfterLast = table[0].Next;

            Assert.AreEqual('0', pointAfterLast.Previous.GetValue());
        }
Ejemplo n.º 3
0
 public TextSnapshot(ITextBuffer owner, PieceTable <char> text, TextSnapshotLines lines)
 {
     _owner       = owner;
     _text        = text;
     _lines       = lines;
     _lines.Owner = this;
 }
Ejemplo n.º 4
0
        private void AddPieceWithAllCategoryToAvailablePieces(PieceTable pieceTable)
        {
            // pieces with All category are always available at the first category
            List <Piece> firstCategory = pieceTable.m_availablePieces.FirstOrDefault();

            if (firstCategory == null)
            {
                return;
            }

            List <Piece> piecesWithAllCategory = firstCategory.FindAll(i => i.m_category == Piece.PieceCategory.All);

            for (int i = 0; i < (int)PieceCategoryMax; i++)
            {
                int index = 0;

                foreach (var piece in piecesWithAllCategory)
                {
                    // m_availablePieces are already populated. Add pieces at the beginning of the list, to replicate vanilla behaviour

                    if (pieceTable.m_availablePieces[i].Contains(piece))
                    {
                        pieceTable.m_availablePieces[i].Remove(piece);
                    }

                    pieceTable.m_availablePieces[i].Insert(Mathf.Min(index, pieceTable.m_availablePieces.Count), piece);
                    index++;
                }
            }
        }
Ejemplo n.º 5
0
 public static void PieceTable_SetCategory(PieceTable __instance, int index)
 {
     if (PieceTableCategories.currentActive != null)
     {
         PieceTableCategories.currentActive.PieceTable_SetCategory(__instance, index);
     }
 }
Ejemplo n.º 6
0
 static bool Prefix(Player __instance, bool takeInput, float dt, PieceTable ___m_buildPieces, GameObject ___m_placementGhost)
 {
     if (!AllowByKey() || !CheckKeyHeld(pullItemsKey.Value) || !__instance.InPlaceMode() || !takeInput || Hud.IsPieceSelectionVisible())
     {
         return(true);
     }
     if (ZInput.GetButtonDown("Attack") || ZInput.GetButtonDown("JoyPlace"))
     {
         Piece selectedPiece = ___m_buildPieces.GetSelectedPiece();
         if (selectedPiece != null)
         {
             if (selectedPiece.m_repairPiece)
             {
                 return(true);
             }
             if (___m_placementGhost != null)
             {
                 int placementStatus = (int)typeof(Player).GetField("m_placementStatus", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                 if (placementStatus == 0)
                 {
                     Dbgl($"pulling resources to player inventory for piece {selectedPiece.name}");
                     PullResources(__instance, selectedPiece.m_resources, 0);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
        public void IntensiveEditingSession()
        {
            var table = PieceTable.ForArray(new int[0]);

            const int iterations             = 10 * 1000;
            const int insertionsPerIteration = 30;
            const int deletionsPerIteration  = 2;

            var random    = new Randomizer(42);
            var totalTime = BenchmarkIterations(iterations, delegate
            {
                var insertionPoint = random.Next(table.Length);
                for (var i = 0; i < insertionsPerIteration; ++i)
                {
                    table = table.Insert(insertionPoint + i, i);
                }

                var readPosition = random.Next(table.Length);
                table.ToArray(readPosition, Math.Min(table.Length - readPosition, insertionsPerIteration));

                for (var i = 0; i < deletionsPerIteration; ++i)
                {
                    table = table.Delete(random.Next(table.Length), 1);
                }
            });

            const int totalNumberOfOperations = iterations * (insertionsPerIteration + deletionsPerIteration);

            ReportTotalNumberOfOperations(totalTime, totalNumberOfOperations);
            Assert.AreEqual(iterations * insertionsPerIteration - iterations * deletionsPerIteration, table.Length);
        }
		public TextSnapshot(ITextBuffer owner, PieceTable<char> text, TextSnapshotLines lines)
		{
			_owner = owner;
			_text = text;
			_lines = lines;
			_lines.Owner = this;
		}
Ejemplo n.º 9
0
 private Piece SetPieceTablePosition(string pieceTableName, string pieceName, int position)
 {
     logger.LogInfo("Moving " + pieceName + " to position " + position + " in " + pieceTableName);
     Object[] array = Resources.FindObjectsOfTypeAll(typeof(PieceTable));
     for (int i = 0; i < array.Length; i++)
     {
         pieceTable = (PieceTable)array[i];
         string name = pieceTable.gameObject.name;
         if (pieceTableName == name)
         {
             logger.LogInfo("Found PieceTable " + pieceTableName);
             int currentPosition = pieceTable.m_pieces.FindIndex(piece => piece.name == pieceName);
             if (currentPosition >= 0)
             {
                 logger.LogInfo("Found Piece " + pieceName + " at position " + currentPosition);
                 GameObject @object = pieceTable.m_pieces[currentPosition];
                 pieceTable.m_pieces.RemoveAt(currentPosition);
                 logger.LogInfo("Moving to position " + position);
                 pieceTable.m_pieces.Insert(position, @object);
                 return(@object.GetComponent <Piece>());
             }
         }
     }
     return(null);
 }
Ejemplo n.º 10
0
 public static void Postfix(ref PieceTable __instance)
 {
     if (BuildExpansionMod.isEnabled.Value)
     {
         HudPatches.needRefresh = true;
     }
 }
		public static IEnumerable<LineSpan> LineSpansFor(PieceTable<char> text)
		{
			var length = text.Length;
			if (length == 0)
			{
				yield return new LineSpan(0, 0, 0);
				yield break;
			}

			var offset = 0;
			var textLength = 0;
			var iterator = text[0];
			do
			{
				var c = iterator.GetValue();
				if (c == '\n')
				{
					const int lineBreakLength = 1;
					yield return new LineSpan(offset, textLength, lineBreakLength);
					offset += textLength + lineBreakLength;
					textLength = 0;
				}
				else
					++textLength;

				iterator = iterator.Next;
			}
			while (iterator.Position < length);

			if (textLength > 0 || iterator.Previous.GetValue() == '\n')
				yield return new LineSpan(offset, textLength, 0);
		}
Ejemplo n.º 12
0
 public static bool Prefix(ref PieceTable __instance)
 {
     if (BuildExpansionMod.isEnabled.Value)
     {
         if (__instance.m_availablePieces[(int)__instance.m_selectedCategory].Count <= 1)
         {
             return(false);
         }
         int        lastRowElems = Player.m_localPlayer.GetBuildPieces().Count % BuildExpansionMod.newGridWidth.Value;
         Vector2Int vector2Int   = __instance.m_selectedPiece[(int)__instance.m_selectedCategory];
         vector2Int.y = vector2Int.y + 1;
         if (vector2Int.y >= HudPatches.calculatedRows)
         {
             vector2Int.y = 0;
         }
         if (vector2Int.y >= HudPatches.calculatedRows - 1 && lastRowElems != 0 && vector2Int.x > lastRowElems - 1)
         {
             vector2Int.x = lastRowElems - 1;
         }
         __instance.m_selectedPiece[(int)__instance.m_selectedCategory] = vector2Int;
         HudPatches.visibilityInsurance.CenterOnItem(Hud.instance.m_pieceIcons[vector2Int.x + vector2Int.y * BuildExpansionMod.newGridWidth.Value].m_go.transform as RectTransform);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 13
0
 public static void PieceTable_PrevCategory_Postfix(PieceTable __instance, ref Piece.PieceCategory __state)
 {
     if (PieceTableCategories.currentActive != null)
     {
         PieceTableCategories.currentActive.PieceTable_PrevCategory(__instance, __state);
     }
 }
Ejemplo n.º 14
0
        public void InsertFollowedByInsert(int index, string s)
        {
            var v0 = PieceTable.ForString(s);
            var v1 = v0.Insert(index, '*');
            var v2 = v1.Insert(index + 1, '-');

            Assert.AreEqual(s.Insert(index, "*-"), StringFor(v2));
        }
Ejemplo n.º 15
0
        public void InsertingAdjacentElementDoesNotCausePieceTableGrowth(string s, int index)
        {
            var v0 = PieceTable.ForString(s);
            var v1 = v0.Insert(index, '*');
            var v2 = v1.Insert(index + 1, '-');

            Assert.AreEqual(v1.PieceCount, v2.PieceCount);
        }
Ejemplo n.º 16
0
        public void Delete(int position, int length, string expectedString)
        {
            const string originalString = "0123";
            var          v0             = PieceTable.ForString(originalString);
            var          v1             = v0.Delete(position, length);

            Assert.AreEqual(expectedString, StringFor(v1));
        }
Ejemplo n.º 17
0
        public void ItRemovesTextAtTheEnd()
        {
            var tbl = new PieceTable("Hello worldasdasd");

            tbl.Remove(11, 6);

            Assert.AreEqual("Hello world", tbl.ToString());
        }
Ejemplo n.º 18
0
        public void ItRemovesTextAtTheBeginning()
        {
            var tbl = new PieceTable("asdasd Hello world");

            tbl.Remove(0, 7);

            Assert.AreEqual("Hello world", tbl.ToString());
        }
Ejemplo n.º 19
0
        public void ItRemovesText()
        {
            var tbl = new PieceTable("Hello asdasd world");

            tbl.Remove(6, 7);

            Assert.AreEqual("Hello world", tbl.ToString());
        }
Ejemplo n.º 20
0
        public void ItInsertsTextInTheMiddle()
        {
            var tbl = new PieceTable("Lorem dolor sit amet");

            tbl.Insert(" ipsum", 5);

            Assert.AreEqual("Lorem ipsum dolor sit amet", tbl.ToString());
        }
Ejemplo n.º 21
0
        internal void ScanHammer(bool lateAdd)
        {
            try
            {
                logger.LogDebug("Scanning Hammer PieceTable for Pieces");
                foreach (GameObject hammerRecipe in PieceManager.Instance.GetPieceTable("Hammer").m_pieces)
                {
                    if (hammerRecipe == null)
                    {
                        logger.LogWarning("null recipe in Hammer PieceTable");
                        continue;
                    }
                    Piece piece = hammerRecipe.GetComponent <Piece>();

                    if (piece.name == "piece_repair")
                    {
                        if (!addedHammer)
                        {
                            PieceTable planHammerPieceTable = PieceManager.Instance.GetPieceTable(PlanHammerPrefabConfig.pieceTableName);
                            if (planHammerPieceTable != null)
                            {
                                planHammerPieceTable.m_pieces.Add(hammerRecipe);
                                addedHammer = true;
                            }
                        }
                        continue;
                    }
                    if (planPiecePrefabConfigs.ContainsKey(piece.name))
                    {
                        continue;
                    }
                    if (!piece.m_enabled ||
                        piece.GetComponent <Ship>() != null ||
                        piece.GetComponent <Plant>() != null ||
                        piece.GetComponent <TerrainModifier>() != null ||
                        piece.m_resources.Length == 0)
                    {
                        continue;
                    }
                    PlanPiecePrefabConfig prefabConfig = new PlanPiecePrefabConfig(piece);
                    PieceManager.Instance.AddPiece(prefabConfig);
                    planPiecePrefabConfigs.Add(piece.name, prefabConfig);
                    PrefabManager.Instance.RegisterToZNetScene(prefabConfig.PiecePrefab);
                    if (lateAdd)
                    {
                        PieceTable pieceTable = PieceManager.Instance.GetPieceTable(PlanHammerPrefabConfig.pieceTableName);
                        if (!pieceTable.m_pieces.Contains(prefabConfig.PiecePrefab))
                        {
                            pieceTable.m_pieces.Add(prefabConfig.PiecePrefab);
                        }
                    }
                }
            }
            finally
            {
                PieceManager.OnPiecesRegistered -= ScanHammer;
            }
        }
Ejemplo n.º 22
0
        public void GetRangeAfterMultipleInserts(int position, int length, string expectedString)
        {
            const string originalString = "01234567";
            var          v0             = PieceTable.ForString(originalString);
            var          v1             = v0.Insert(2, '*');
            var          v2             = v1.Insert(v1.Length - 2, '*');

            Assert.AreEqual(expectedString, new string(v2.ToArray(position, length)));
        }
Ejemplo n.º 23
0
        public void InsertPreservesOriginalVersion()
        {
            const string originalString = "01234567";
            var          v0             = PieceTable.ForString(originalString);
            var          v1             = v0.Insert(2, '*');

            Assert.AreEqual(originalString.Insert(2, "*"), StringFor(v1));
            Assert.AreEqual(originalString, StringFor(v0));
        }
Ejemplo n.º 24
0
        public void DeleteAfterInsert(int position, int length, string expectedString)
        {
            const string originalString = "023";
            var          v0             = PieceTable.ForString(originalString);
            var          v1             = v0.Insert(1, '1');
            var          v2             = v1.Delete(position, length);

            Assert.AreEqual(expectedString, StringFor(v2));
        }
Ejemplo n.º 25
0
        public void LengthAfterPrepending(int insertionCount)
        {
            var table = PieceTable.ForString("");

            for (var i = 0; i < insertionCount; ++i)
            {
                table = table.Insert(0, ' ');
            }
            Assert.AreEqual(insertionCount, table.Length);
        }
Ejemplo n.º 26
0
 public void PieceTable_SetCategory(PieceTable self, int index)
 {
     if (self.m_useCategories)
     {
         if (ContainsValue((Piece.PieceCategory)index))
         {
             self.m_selectedCategory = (Piece.PieceCategory)index;
         }
     }
 }
Ejemplo n.º 27
0
        public void ItLoadsContent()
        {
            var tbl = new PieceTable("original");

            Assert.AreEqual("original", tbl.Original);
            Assert.AreEqual(1, tbl.Pieces.Count);
            Assert.AreEqual(0, tbl.Pieces[0].Start);
            Assert.AreEqual("original".Length, tbl.Pieces[0].Length);
            Assert.AreEqual(false, tbl.Pieces[0].AddBuffer);
        }
Ejemplo n.º 28
0
        public void ItInsertsMultipleTexts()
        {
            var tbl = new PieceTable();

            tbl.Insert("Hello world", 0);
            tbl.Insert(" wonderful", 5);
            tbl.Insert(", this is a test!", tbl.ToString().Length);

            Assert.AreEqual("Hello wonderful world, this is a test!", tbl.ToString());
        }
Ejemplo n.º 29
0
        private static PieceTable <int> CreateTableWithManyPieces(int length)
        {
            var table = PieceTable.ForArray(new int[0]);

            for (var i = 0; i < length; ++i)
            {
                table = table.Insert(0, i);
            }
            return(table);
        }
Ejemplo n.º 30
0
        public override CalculatedFieldValue GetCalculatedValueCore(PieceTable sourcePieceTable,
                                                                    MailMergeDataMode mailMergeDataMode,
                                                                    Field documentField)
        {
            OfficeImage   image       = chart.CreateImage();
            DocumentModel targetModel = sourcePieceTable.DocumentModel.GetFieldResultModel();

            targetModel.MainPieceTable.InsertInlinePicture(DocumentLogPosition.Zero, image);
            return(new CalculatedFieldValue(targetModel));
        }
Ejemplo n.º 31
0
        public void DeletionPieceCountAfterInsert(int position, int length, int expectedPieceCount)
        {
            var v0 = PieceTable.ForString("02");
            var v1 = v0.Insert(1, '1');

            Assert.AreEqual(3, v1.PieceCount);

            var v2 = v1.Delete(position, length);

            Assert.AreEqual(expectedPieceCount, v2.PieceCount);
        }
Ejemplo n.º 32
0
        public void SequentialAccessAfterManyDeletions()
        {
            const int numberOfDeletions  = 100;
            const int numberOfCharacters = 500;
            const int iterations         = 10 * 1000;

            var randomizer = new Randomizer(42);

            var table = PieceTable.ForString(new string(' ', 5 * 1024));

            for (var i = 0; i < numberOfDeletions; ++i)
            {
                table = table.Delete(randomizer.Next(table.Length), 1);
            }

            Console.WriteLine("** CopyTo iteration **");
            var buffer       = new char[1];
            var totalWithout = BenchmarkIterations(iterations, delegate
            {
                var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters;
                for (var i = 0; i < numberOfCharacters; ++i)
                {
                    table.CopyTo(buffer, 0, position + i, 1);
                }
                for (var i = 0; i < numberOfCharacters; ++i)
                {
                    table.CopyTo(buffer, 0, position - i, 1);
                }
            });
            const int totalNumberOfOperations = iterations * numberOfCharacters;

            ReportTotalNumberOfOperations(totalWithout, totalNumberOfOperations);

            Console.WriteLine("** Point iteration **");
            var totalWith = BenchmarkIterations(iterations, delegate
            {
                var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters;
                var pivot    = table[position];
                var current  = pivot;
                for (var i = 0; i < numberOfCharacters; ++i)
                {
                    current.GetValue();
                    current = current.Next;
                }
                current = pivot;
                for (var i = 0; i < numberOfCharacters; ++i)
                {
                    current.GetValue();
                    current = current.Previous;
                }
            });

            ReportTotalNumberOfOperations(totalWith, totalNumberOfOperations);
        }
		private static string StringFor(PieceTable<char> p)
		{
			return new string(p.ToArray());
		}
		public TextSnapshot(ITextBuffer owner, PieceTable<char> text) : this(owner, text, new TextSnapshotLines(text))
		{
		}
		public TextSnapshotLines(PieceTable<char> text)
		{
			_spans = PieceTable.ForArray(LineParser.LineSpansFor(text).ToArray());
		}