Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from mxashlynn/extend-item-parquets
Browse files Browse the repository at this point in the history
Extend Collectable Parquets
  • Loading branch information
mxashlynn committed Mar 28, 2019
2 parents 831980a + 96286dc commit 50acad0
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 186 deletions.
19 changes: 11 additions & 8 deletions Designer/Collectable.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
ID,Name,AddsToBiome
-40000,4 Collectable Test Parquet,None
40000,Flower,None
40001,Pinecone,Forested
40002,Seeds,Swamp
40003,Bones,Desert
40004,Ice Crystal,Tundra
40005,Copper Ore,Cavern
ID,Name,AddsToBiome,Effect,EffectAmount,ItemID
-40000,4 Collectable Test Parquet,None,None,0,-50000
40000,Flower,None,Item,0,50000
40001,Pinecone,Forested,Item,0,50001
40002,Seeds,Swamp,Item,0,50002
40003,Bones,Desert,Item,0,50003
40004,Ice Crystal,Tundra,Item,0,50004
40005,Copper Ore,Cavern,Item,0,50005
40006,Heart,None,Health,10,0
40007,Star,None,Mana,10,0
40008,Coin,None,Money,1,0
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ namespace ParquetCSVImporter
/// <summary>
/// ID Converter for parquet identifiers.
/// </summary>
public class ParquetIDConverter : DefaultTypeConverter
public class EntityIDConverter : DefaultTypeConverter
{
/// <summary>
/// Converts the given record column to <see cref="ParquetID"/>.
/// Converts the given record column to <see cref="EntityID"/>.
/// </summary>
/// <param name="text">The record column to convert to an object.</param>
/// <param name="row">The <see cref="IReaderRow"/> for the current record.</param>
/// <param name="memberMapData">The <see cref="MemberMapData"/> for the member being created.</param>
/// <returns>The <see cref="ParquetID"/> created from the record column.</returns>
/// <returns>The <see cref="EntityID"/> created from the record column.</returns>
public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
{
var numberStyle = memberMapData.TypeConverterOptions.NumberStyle ?? NumberStyles.Integer;

if (int.TryParse(text, numberStyle, memberMapData.TypeConverterOptions.CultureInfo, out var i))
{
return (ParquetID)i;
return (EntityID)i;
}

return (ParquetID)base.ConvertFromString(text, row, memberMapData);
return (EntityID)base.ConvertFromString(text, row, memberMapData);
}
}
}
4 changes: 2 additions & 2 deletions ParquetCSVImporter/ImportProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private static IEnumerable<T> GetRecordsForType<T>()
{
using (var csv = new CsvReader(reader))
{
csv.Configuration.TypeConverterCache.AddConverter(typeof(ParquetID), new ParquetIDConverter());
csv.Configuration.TypeConverterOptionsCache.AddOptions(typeof(ParquetID), IdentifierOptions);
csv.Configuration.TypeConverterCache.AddConverter(typeof(EntityID), new EntityIDConverter());
csv.Configuration.TypeConverterOptionsCache.AddOptions(typeof(EntityID), IdentifierOptions);
csv.Configuration.RegisterClassMapFor<T>();
records = csv.GetRecordsViaShim<T>();
}
Expand Down
2 changes: 1 addition & 1 deletion ParquetCSVImporter/ParquetCSVImporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<Compile Include="Shims\FloorShim.cs" />
<Compile Include="Shims\FurnishingShim.cs" />
<Compile Include="Shims\ParquetParentShim.cs" />
<Compile Include="ParquetIDConverter.cs" />
<Compile Include="EntityIDConverter.cs" />
<Compile Include="ClassMaps\IReaderConfigurationExtensions.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 15 additions & 2 deletions ParquetCSVImporter/Shims/CollectableShim.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ParquetClassLibrary.Sandbox.Parquets;
using ParquetClassLibrary.Sandbox.ID;
using ParquetClassLibrary.Sandbox.Parquets;

namespace ParquetCSVImporter.ClassMaps
{
Expand All @@ -12,6 +13,18 @@ namespace ParquetCSVImporter.ClassMaps
/// </summary>
public class CollectableShim : ParquetParentShim
{
/// <summary>The effect generated when a character encounters this Collectable.</summary>
public CollectionEffect Effect;

/// <summary>
/// The scale in points of the effect. That is, how much to alter a stat if the
/// <see cref="T:ParquetClassLibrary.Sandbox.ID.CollectionEffect"/> is set to alter a stat.
/// </summary>
public int EffectAmount;

/// <summary>The item spawned when a character encounters this Collectable.</summary>
public EntityID ItemID;

/// <summary>
/// Converts a shim into the class is corresponds to.
/// </summary>
Expand All @@ -26,7 +39,7 @@ public override T To<T>()

if (typeof(T) == typeof(Collectable))
{
result = (T)(ParquetParent)new Collectable(ID, Name, AddsToBiome);
result = (T)(ParquetParent)new Collectable(ID, Name, AddsToBiome, Effect, EffectAmount, ItemID);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion ParquetCSVImporter/Shims/ParquetParentShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ParquetCSVImporter.ClassMaps
public abstract class ParquetParentShim
{
/// <summary>Unique identifier of the parquet.</summary>
public ParquetID ID;
public EntityID ID;

/// <summary>Player-facing name of the parquet.</summary>
public string Name;
Expand Down
27 changes: 17 additions & 10 deletions ParquetClassLibrary/Assembly.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ParquetClassLibrary.Sandbox.ID;
using ParquetClassLibrary.Sandbox.ID;
using ParquetClassLibrary.Utilities;

// Allow unit tests to access classes and members with internal accessibility.
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ParquetUnitTests")]

namespace ParquetClassLibrary
Expand All @@ -13,30 +14,36 @@ public struct Assembly
/// <summary>Describes the version of the serialized data that this class understands.</summary>
public const string SupportedDataVersion = "0.1.0";

#region Sandbox Parquet ID Ranges
#region Sandbox Parquet and Item ID Ranges
/// <summary>
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ParquetID"/> set aside for Floors.
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/> set aside for Floors.
/// Valid identifiers may be positive or negative. By convention, negative IDs indicate test parquets.
/// </summary>
public static readonly Range<ParquetID> FloorIDs = new Range<ParquetID>(10000, 19000);
public static readonly Range<EntityID> FloorIDs = new Range<EntityID>(10000, 19000);

/// <summary>
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ParquetID"/> set aside for Blocks.
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/> set aside for Blocks.
/// Valid identifiers may be positive or negative. By convention, negative IDs indicate test parquets.
/// </summary>
public static readonly Range<ParquetID> BlockIDs = new Range<ParquetID>(20000, 29000);
public static readonly Range<EntityID> BlockIDs = new Range<EntityID>(20000, 29000);

/// <summary>
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ParquetID"/> set aside for Furnishings.
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/> set aside for Furnishings.
/// Valid identifiers may be positive or negative. By convention, negative IDs indicate test parquets.
/// </summary>
public static readonly Range<ParquetID> FurnishingIDs = new Range<ParquetID>(30000, 39000);
public static readonly Range<EntityID> FurnishingIDs = new Range<EntityID>(30000, 39000);

/// <summary>
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ParquetID"/> set aside for Collectables.
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/> set aside for Collectables.
/// Valid identifiers may be positive or negative. By convention, negative IDs indicate test parquets.
/// </summary>
public static readonly Range<ParquetID> CollectableIDs = new Range<ParquetID>(40000, 49000);
public static readonly Range<EntityID> CollectableIDs = new Range<EntityID>(40000, 49000);

/// <summary>
/// A subset of the values of <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/> set aside for Items.
/// Valid identifiers may be positive or negative. By convention, negative IDs indicate test items.
/// </summary>
public static readonly Range<EntityID> ItemIDs = new Range<EntityID>(50000, 59000);
#endregion

#region Sandbox Map Element Dimensions
Expand Down
14 changes: 14 additions & 0 deletions ParquetClassLibrary/Sandbox/ID/CollectionEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace ParquetClassLibrary.Sandbox.ID
{
/// <summary>
/// IDs for effects that can happen when a character encounters a Collectable.
/// </summary>
public enum CollectionEffect
{
None,
Item,
Health,
Mana,
Money,
}
}
103 changes: 103 additions & 0 deletions ParquetClassLibrary/Sandbox/ID/EntityID.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using Newtonsoft.Json;
using ParquetClassLibrary.Utilities;

namespace ParquetClassLibrary.Sandbox.ID
{
/// <summary>
/// Uniquely identifies every defined game entity.
///
/// <see cref="ParquetClassLibrary.Sandbox.Parquets.ParquetParent"/>
///
/// To be clear: there are multiple parquet and item subtypes,
/// and each of these subtypes has multiple definitions.
/// The definitions are purely data-driven, read in from
/// JSON or CSV files, and not type-checked by the compiler.
///
/// Multiple identicle parquet IDs may be assigned to MapChunks
/// or MapRegions, and multiple duplicate item IDs may be spawned.
/// The IDs provide a means for the library to look up
/// the game entity definition when other game elements interact
/// with it.
///
/// Although the compiler does not provide type-checking for
/// IDs, within the scope of their usage the library defines
/// valid ranges for their use and these are checked by
/// library code. <see cref="ParquetClassLibrary.Assembly"/>
///
/// TODO: Move this explanation into the Wiki and expand it.
/// </summary>
public struct EntityID : IComparable<EntityID>
{
/// <summary>Indicates the lack of a game entity associated with this identifier (e.g., parquet).</summary>
public static readonly EntityID None = 0;

/// <summary>Backing type for the identifier.</summary>
// Currently this is implemented as an int rather than a GUID in order
// to aid in range validation and human-readability of design documents.
[JsonProperty]
private int _id;

#region IComparable Methods
/// <summary>
/// Enables identifiers to be treated as their backing type.
/// </summary>
/// <param name="in_value">Any valid identifier value.</param>
/// <returns>The given identifier value.</returns>
public static implicit operator EntityID(int in_value)
{
return new EntityID { _id = in_value };
}

/// <summary>
/// Enables identifiers to be treated as their backing type.
/// </summary>
/// <param name="in_identifier">Any valid identifier value.</param>
/// <returns>The given identifier value.</returns>
public static implicit operator int(EntityID in_identifier)
{
return in_identifier._id;
}

/// <summary>
/// Enables identifiers to be compared with other identifiers.
/// </summary>
/// <param name="in_identifier">Any valid identifier value.</param>
/// <returns>
/// A value indicating the relative ordering of the objects being compared.
/// The return value has these meanings:
/// Less than zero indicates that the current instance precedes the given identifier in the sort order.
/// Zero indicates that the current instance occurs in the same position in the sort order as the given identifier.
/// Greater than zero indicates that the current instance follows the given identifier in the sort order.
/// </returns>
public int CompareTo(EntityID in_identifier)
{
return _id.CompareTo(in_identifier._id);
}
#endregion

#region Utility Methods
/// <summary>
/// Validates the current ID. An ID is valid if:
/// 1) it is <see cref="ParquetClassLibrary.Sandbox.ID.EntityID.None"/>
/// 2) it is defined within the given range, regardless of sign.
/// </summary>
/// <returns><c>true</c>, if the identifier is valid given the range, <c>false</c> otherwise.</returns>
/// <param name="in_range">The range within which the absolute value of the ID must fall.</param>
public bool IsValidForRange(Range<EntityID> in_range)
{
return _id == None || in_range.ContainsValue(Math.Abs(_id));
}

/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current
/// <see cref="T:ParquetClassLibrary.Sandbox.ID.EntityID"/>.
/// </summary>
/// <returns>The representation.</returns>
public override string ToString()
{
return _id.ToString();
}
#endregion
}
}
75 changes: 0 additions & 75 deletions ParquetClassLibrary/Sandbox/ID/ParquetID.cs

This file was deleted.

8 changes: 4 additions & 4 deletions ParquetClassLibrary/Sandbox/MapChunk.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public class MapChunk : MapParent

#region Chunk Contents
/// <summary>Floors and walkable terrain in the region.</summary>
protected override ParquetID[,] _floorLayer { get; } = new ParquetID[Assembly.ParquetsPerChunkDimension,
protected override EntityID[,] _floorLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];

/// <summary>Walls and obstructing terrain in the region.</summary>
protected override ParquetID[,] _blockLayer { get; } = new ParquetID[Assembly.ParquetsPerChunkDimension,
protected override EntityID[,] _blockLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];

/// <summary>Furniture and natural items in the region.</summary>
protected override ParquetID[,] _furnishingLayer { get; } = new ParquetID[Assembly.ParquetsPerChunkDimension,
protected override EntityID[,] _furnishingLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];

/// <summary>Collectable materials in the region.</summary>
protected override ParquetID[,] _collectableLayer { get; } = new ParquetID[Assembly.ParquetsPerChunkDimension,
protected override EntityID[,] _collectableLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];
#endregion

Expand Down
Loading

0 comments on commit 50acad0

Please sign in to comment.