|
@@ -136,10 +136,46 @@ function ParseSourceDestinationRange(lineNumber: number, almanac: string[]): Map
|
|
* @param haystack The list to find the ID in
|
|
* @param haystack The list to find the ID in
|
|
* @returns {IdentifiableObject|undefined} The object by that ID if found, or undefined
|
|
* @returns {IdentifiableObject|undefined} The object by that ID if found, or undefined
|
|
*/
|
|
*/
|
|
-function FindObjectByID(needle: number, haystack: IdentifiableObject[]): IdentifiableObject|undefined {
|
|
|
|
|
|
+function FindObjectByID(needle: number, haystack: IdentifiableObject[]|MappableObject[]): IdentifiableObject|MappableObject|undefined {
|
|
return haystack.find((obj) => obj.ID == needle);
|
|
return haystack.find((obj) => obj.ID == needle);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Map a Seed ID to all of its other attributes
|
|
|
|
+ *
|
|
|
|
+ * Given a seed ID, finds its soil type, fertilizer type, water type,
|
|
|
|
+ * light type, temperature type, humidity type, and location ID.
|
|
|
|
+ *
|
|
|
|
+ * @param {number} seedID
|
|
|
|
+ * @param {RangeMaps} rangeMaps A parsed map of ranges
|
|
|
|
+ * @returns
|
|
|
|
+ */
|
|
|
|
+function MapSeed(seedID: number, rangeMaps: RangeMaps): SeedMap|undefined {
|
|
|
|
+ // Make sure the seed with that ID exists before continueing
|
|
|
|
+ if(!FindObjectByID(seedID, rangeMaps.Seeds)) { return undefined; }
|
|
|
|
+
|
|
|
|
+ // Initialize our seed map object
|
|
|
|
+ const seed: SeedMap = {
|
|
|
|
+ ID: seedID,
|
|
|
|
+ SoilID: 0,
|
|
|
|
+ FertilizerID: 0,
|
|
|
|
+ WaterID: 0,
|
|
|
|
+ LightID: 0,
|
|
|
|
+ TemperatureID: 0,
|
|
|
|
+ HumidityID: 0,
|
|
|
|
+ LocationID: 0,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ seed.SoilID = (FindObjectByID(seedID, rangeMaps.SeedToSoil) as MappableObject)?.PointsTo || seedID;
|
|
|
|
+ seed.FertilizerID = (FindObjectByID(seed.SoilID, rangeMaps.SoilToFertilizer) as MappableObject)?.PointsTo || seed.SoilID;
|
|
|
|
+ seed.WaterID = (FindObjectByID(seed.FertilizerID, rangeMaps.FertilizerToWater) as MappableObject)?.PointsTo || seed.FertilizerID;
|
|
|
|
+ seed.LightID = (FindObjectByID(seed.WaterID, rangeMaps.WaterToLight) as MappableObject)?.PointsTo || seed.WaterID;
|
|
|
|
+ seed.TemperatureID = (FindObjectByID(seed.LightID, rangeMaps.LightToTemperature) as MappableObject)?.PointsTo|| seed.LightID;
|
|
|
|
+ seed.HumidityID = (FindObjectByID(seed.TemperatureID, rangeMaps.TemperatureToHumidity) as MappableObject)?.PointsTo || seed.TemperatureID;
|
|
|
|
+ seed.LocationID = (FindObjectByID(seed.HumidityID, rangeMaps.HumidityToLocation) as MappableObject)?.PointsTo || seed.HumidityID;
|
|
|
|
+
|
|
|
|
+ return seed;
|
|
|
|
+}
|
|
|
|
|
|
interface IdentifiableObject {
|
|
interface IdentifiableObject {
|
|
ID: number,
|
|
ID: number,
|
|
@@ -160,4 +196,23 @@ type RangeMaps = {
|
|
LightToTemperature: MappableObject[],
|
|
LightToTemperature: MappableObject[],
|
|
TemperatureToHumidity: MappableObject[],
|
|
TemperatureToHumidity: MappableObject[],
|
|
HumidityToLocation: MappableObject[],
|
|
HumidityToLocation: MappableObject[],
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type SeedMap = {
|
|
|
|
+ /** The ID of the seed */
|
|
|
|
+ ID: number,
|
|
|
|
+ /** The ID of the soil type the seed needs planted in */
|
|
|
|
+ SoilID: number,
|
|
|
|
+ /** The ID of the fertilizer type the soil needs */
|
|
|
|
+ FertilizerID: number,
|
|
|
|
+ /** The ID of the water type the fertilizer needs */
|
|
|
|
+ WaterID: number,
|
|
|
|
+ /** The ID of the light type the water needs */
|
|
|
|
+ LightID: number,
|
|
|
|
+ /** The ID of the temperature type the light needs */
|
|
|
|
+ TemperatureID: number,
|
|
|
|
+ /** The ID of the humidity type the temperature needs */
|
|
|
|
+ HumidityID: number,
|
|
|
|
+ /** The ID of the location the humidity needs */
|
|
|
|
+ LocationID: number,
|
|
}
|
|
}
|