-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathambient.d.ts
196 lines (174 loc) · 4.14 KB
/
ambient.d.ts
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
declare global {
type InteractionEvent = MouseEvent | PointerEvent | TouchEvent | KeyboardEvent
type FoodId =
| "f01"
| "f02"
| "f03"
| "f04"
| "f05"
| "f06"
| "f07"
| "f08"
| "f09"
| "f10"
| "f11"
| "f12"
| "f13"
| "f14"
interface Food {
id: FoodId
name: string
type: string
emoji: string
image?: string
proteinType: string
landAllocation: number
yieldPerHa: number
productionSources: string
proteinRatio: number
calorieRatio: number
carbRatio: number
fatRatio: number
nutritionSources: string
ghgPerKg: number
waterPerKg: number
eutrophyPerKg: number
landPerKg: number
impactSources: string
description?: string
colorId?: string
}
type FoodItemsGrouped = { [key: "animal" | "plant"]: Food[] }
type UnitId =
| "emissions"
| "landUse"
| "waterUse"
| "eutrophy"
| "yield"
| "protein"
| "calories"
| "protein-per-capita"
interface Unit {
id: UnitId
name: string
suffix: string
suffixFull: string
description: string
sources: string
}
interface Region {
id: string
name: string
population: number
dailyProteinPerCapita: number
dailyCaloriesPerCapita: number
cropLandAvailable: number
grazingLandAvailable: number
waterAvailable: number
cropLandUsed: number
grazingLandUsed: number
waterAgriculturalUsed: number
ghgAnnual: number
ghgAgriculturalAnnual: number
note: string
}
// GameState related types
type InventoryItem = { id: FoodId; name: string; available: number }
// Fail/success related types
class GameSnapshot {
year: number
proteinPerPersonPerDay: number
emissionsChange: number
waterUseChange: number
eutrophyChange: number
hasSucceeded: boolean
hasFailed: boolean
}
interface LineChartSettings {
yDatum?: number
yLimit?: number
yMax?: number
yMin?: number
}
type FailureMetricKey =
| "proteinPerPersonPerDay"
| "emissionsChange"
| "waterUseChange"
| "eutrophyChange"
interface FailureMetric {
value: number
key: FailureMetricKey
label: string
suffix: string
limit: number
objective: string
warn: boolean
fail: boolean
history: number[]
farmMetricKey: FarmMetricKey
foodMetricKey: keyof Food
chartSettings: LineChartSettings
}
interface SuccessMetrics {
hectaresPerPerson: number
peopleAdequateCalories: number
calorieProductionChange: number
caloriesPerPersonPerDayValue: number
proteinPerPersonPerDay: FailureMetric
emissionsChange: FailureMetric
waterUseChange: FailureMetric
eutrophyChange: FailureMetric
hasSucceeded: boolean
hasFailed: boolean
}
// Farm related types
type FarmKey = keyof Farm
type FarmGrid = Food[][]
type FarmMetricFoodList = { value: number; count: number; food: Food; unit: Unit }
type FarmMetricKey = Exclude<keyof FarmState, "grid"> // key of FarmState without "grid"
interface FarmMetric {
total: number
byFood: FarmMetricFoodList[]
}
interface FarmState {
grid: FarmGrid
yield: FarmMetric
landUse: FarmMetric
waterUse: FarmMetric
eutrophy: FarmMetric
emissions: FarmMetric
protein: FarmMetric
calories: FarmMetric
}
interface Count {
food: Food
initial: number
current: number
delta: number
}
class Farm {
constructor(settings: GameSettings | null)
// properties
initialState: FarmState
grid: FarmGrid
items: string[]
rows: number
cols: number
// methods
getInitialState(): FarmState
getFarmMetric(fn: (item: Food) => number): FarmMetric
plantCrop(x: number, y: number, foodItem: Food): void
getTotalSum(fn: (item: Food) => number): number
getSumByFoodType(fn: (item: Food) => number): FarmGridFoodList[]
// getters
readonly yield: FarmMetric
readonly landUse: FarmMetric
readonly waterUse: FarmMetric
readonly emissions: FarmMetric
readonly eutrophy: FarmMetric
readonly protein: FarmMetric
readonly calories: FarmMetric
readonly foodChanges: Count[]
}
}
export {}