private void updateStats() { bool inLevel = LauncherWrapper.IsInLevel(); if (!inLevel) { // Update FPS only ((CompoundItem)Items[0]).Items[0].Update(); return; } else { // Update all stats int attributes = LauncherWrapper.GetPlayerAttributesLength(); if (attributes != attributeLength) { InitItems(); } attributeLength = attributes; LauncherWrapper.updatePlayer(); foreach (TreeItem item in Items) { item.Update(); } } }
public void InitItems() { Items.Clear(); CompoundItem renderStats = new CompoundItem() { Name = "Rendering Stats" }; { renderStats.Items.Add(new PrimitiveItem <float>() { Name = "FPS", GetValue = LauncherWrapper.GetFPS, Description = "Average frames per second" }); renderStats.Items.Add(new PrimitiveItem <int>() { Name = "Visible Entities", GetValue = LauncherWrapper.GetEntitiesOnScreen, Description = "Number of entities being rendered on the screen" }); } Items.Add(renderStats); CompoundItem playerStats = new CompoundItem() { Name = "Player Stats", Description = "Stats about the local player" }; { CompoundValueItem <Vec3> playerPositionStats = new CompoundValueItem <Vec3>() { Name = "Position", GetValue = LauncherWrapper.GetPlayerPosition, Description = "Position of the player using world coordinates", IsExpanded = false }; { playerPositionStats.Items.Add(new PrimitiveItem <Vec3>() { Name = "Block", GetValue = LauncherWrapper.GetPlayerBlockPosition, Description = "Position of the player to the nearest block" }); playerPositionStats.Items.Add(new PrimitiveItem <Vec3>() { Name = "Chunk", GetValue = LauncherWrapper.GetPlayerChunkPosition, Description = "Position of the player to the nearest chunk" }); } playerStats.Items.Add(playerPositionStats); CompoundValueItem <Vec2> rotationStats = new CompoundValueItem <Vec2>() { Name = "Rotation", GetValue = LauncherWrapper.GetPlayerRotation, Description = "The rotation of the player", IsExpanded = false }; { rotationStats.Items.Add(new PrimitiveItem <float>() { Name = "Pitch", GetValue = LauncherWrapper.GetPlayerPitch, Description = "Up/down rotation" }); rotationStats.Items.Add(new PrimitiveItem <float>() { Name = "Yaw", GetValue = LauncherWrapper.GetPlayerYaw, Description = "Y-Axis rotation" }); rotationStats.Items.Add(new EnumItem <BlockFace>() { Name = "Facing", GetValue = LauncherWrapper.GetPlayerFacingDirection, Description = "Direction the player is facing" }); } playerStats.Items.Add(rotationStats); playerStats.Items.Add(new PrimitiveItem <int>() { Name = "Age", GetValue = LauncherWrapper.GetPlayerAge, Description = "How old the player is (measured in game ticks)" }); playerStats.Items.Add(new PrimitiveItem <float>() { Name = "Distance Travelled", GetValue = LauncherWrapper.GetPlayerDistanceTravelled, Description = "Distance the player travelled on foot while playing the level" }); playerStats.Items.Add(new StructItem <IntVec2>() { Name = "Sky/Block Light", GetValue = LauncherWrapper.GetLightValues, Description = "Sky and block light values for the block the player is looking at (Not always accurate)" }); CompoundItem itemInHandStats = new CompoundEnumItem <DataValue>() { Name = "Item In Hand", GetValue = LauncherWrapper.GetItemIdEnum, Description = "Information about the item the player is holding", IsExpanded = false }; { itemInHandStats.Items.Add(new PrimitiveItem <short>() { Name = "Id", GetValue = LauncherWrapper.GetItemId, Description = "The Id of the item" }); itemInHandStats.Items.Add(new PrimitiveItem <short>() { Name = "Damage", GetValue = LauncherWrapper.GetItemDamage, Description = "Extra data or damage used to define the item" }); itemInHandStats.Items.Add(new PrimitiveItem <short>() { Name = "Count", GetValue = LauncherWrapper.GetItemAmount, Description = "How much of the item the player has" }); } playerStats.Items.Add(itemInHandStats); CompoundValueItem <HitResult> lookingAtInfo = new CompoundValueItem <HitResult>() { Name = "Looking At", GetValue = LauncherWrapper.GetHitResultType, Description = "The object the player is currently looking at", IsExpanded = false }; { lookingAtInfo.Items.Add(new StructItem <Vec3>() { Name = "Position", GetValue = LauncherWrapper.GetPlayerLookingAt, Description = "Position of where the player is looking" }); lookingAtInfo.Items.Add(new HitResultItem() { Name = "Info", GetValue = LauncherWrapper.GetHitResultType, Description = "Extra data about the object the player is looking at" }); } playerStats.Items.Add(lookingAtInfo); int totalAttributes = LauncherWrapper.GetPlayerAttributesLength(); if (totalAttributes > 0 && totalAttributes != 31) { CompoundItem attributeStats = new CompoundItem() { Name = "Attributes", Description = "Player attributes", IsExpanded = false }; { for (int ind = 0; ind < totalAttributes; ind++) { StringBuilder attributeName = new StringBuilder(31); int length = LauncherWrapper.GetPlayerAttributeName(ind, attributeName); string name = attributeName.ToString(); if (String.IsNullOrEmpty(name)) { continue; } int strInd = name.IndexOf(".") + 1; name = name.Substring(strInd, length - strInd); name = char.ToUpper(name[0]) + name.Substring(1); attributeStats.Items.Add(new AttributeItem() { Name = name, Index = ind, GetValue = LauncherWrapper.GetPlayerAttributValues, Description = EntityUtils.getAttributeDescription(name) }); } } playerStats.Items.Add(attributeStats); } } Items.Add(playerStats); CompoundItem levelStats = new CompoundItem() { Name = "Level Stats", Description = "Stats about the current level" }; { levelStats.Items.Add(new StringItem() { Name = "Level Name", GetValue = LauncherWrapper.GetLevelName, GetLength = LauncherWrapper.GetLevelNameLength, MaxLength = 40, Description = "The name of the current level" }); levelStats.Items.Add(new TimeItem() { Name = "Time", GetValueA = LauncherWrapper.GetLevelTime, GetValueB = LauncherWrapper.GetLevelTimeOfDay, Description = "Number of ticks since the world was started; used in-game to keep track of time" }); /* * CompoundItem weatherStats = new CompoundItem() { Name = "Weather", Description = "Stats about the weather" }; * { * * } */ } Items.Add(levelStats); }