-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCrop.cs
105 lines (92 loc) · 3.21 KB
/
Crop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using StardewModdingAPI;
using Newtonsoft.Json.Linq;
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
namespace LastDayToPlant
{
public class Crop
{
public string Name { get; set; }
public int DaysToGrow { get; set; }
public List<Season> Seasons { get; set; }
public int DaysToGrowIrrigated { get; set; } = 0;
public int AvailableYear { get; set; } = 1;
public bool GingerIsland { get; set; } = false;
public string Message { get; set; }
public string MessageSpeedGro { get; set; }
public string MessageDelxueSpeedGro { get; set; }
public string MessageHyperSpeedGro { get; set; }
public Crop(string name, int daysToGrow)
{
Name = name;
DaysToGrow = daysToGrow;
}
public Crop() { }
public bool IsLastGrowSeason(Season season)
{
var seasons = Seasons.OrderByDescending(x => x);
return seasons.First() == season;
}
public void Localize(IModHelper helper, string baseName)
{
// This one can't be handled by I18n because it's dynamic
Name = helper.Translation.Get($"crop.{baseName.Replace(" ", "")}");
// The rest of the messages can though
Message = I18n.Notification_Crop_NoFertilizer(Name);
MessageSpeedGro = I18n.Notification_Crop_SpeedGro(Name);
MessageDelxueSpeedGro = I18n.Notification_Crop_DeluxeSpeedGro(Name);
MessageHyperSpeedGro = I18n.Notification_Crop_HyperSpeedGro(Name);
}
public static Crop FromModFile(string cropFilePath)
{
var jsonObject = JObject.Parse(File.ReadAllText(cropFilePath));
var crop = new Crop()
{
Name = jsonObject["Name"].ToString()
};
// Seasons
var seasons = jsonObject["Seasons"].ToObject<string[]>();
crop.Seasons = new List<Season>();
foreach (var season in seasons)
{
crop.Seasons.Add(GetSeasonEnum(season));
}
// Days to Grow
var desc = jsonObject["SeedDescription"].ToString();
var startWord = "Takes";
var endWord = "mature";
if (!desc.Contains(startWord))
{
startWord = "in";
endWord = "days";
}
var start = desc.IndexOf(startWord);
var end = desc.IndexOf(endWord);
if(start == -1 || end == -1)
{
crop.DaysToGrow = 0;
return crop;
}
var splits = desc.Substring(start, end - start).Split(' ');
foreach(var split in splits)
{
var isNumber = int.TryParse(split, out int days);
if (isNumber)
{
crop.DaysToGrow = days;
}
}
return crop;
}
private static Season GetSeasonEnum(string season)
{
return (Season)Enum.Parse(typeof(Season), season);
}
public override string ToString()
{
return Name;
}
}
}