-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.gs
338 lines (308 loc) · 11.3 KB
/
Code.gs
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//2645 lines of code AUG 2020
//1005 lines from Dec 21 2020 cleanup!
const ui = SpreadsheetApp.getUi();
const ss = SpreadsheetApp.getActiveSpreadsheet();
class Division {
constructor(name, abbrev, scorerange){
this.name = name;
this.abbrev = abbrev;
this.sheet = ss.getSheetByName(name);
// Division's own score on their own board
// arg for reset board & score check
this.score = scorerange;
this.Capacity = this.sheet.getRange('C2')
this.Actions = this.sheet.getRange('A2')
this.Open = this.sheet.getRange('G2')
this.Extra = this.sheet.getRange('E2')
this.Victory = this.sheet.getRange('F49')
this.Highcap = this.sheet.getRange('F47')
this.titleboard = this.sheet.getRange('H20')
this.msgboard = this.sheet.getRange('H23')
}
// any number of arguments (...)
getRange(...range) {
return this.sheet.getRange(...range)
}
acquiredReveal() {
var GLAheader = []
var GLAvalue = []
for (var i=1; i < 26; i++){
let acqRange = this.sheet.getRange("3",i);
let HLRange = this.sheet.getRange("5",i);
let acqRange2 = this.sheet.getRange("8",i);
let HLRange2 = this.sheet.getRange("6",i);
if (acqRange.isBlank() == false) {
HLRange.clearFormat()
var p = acqRange.getValue()
var abbrev = new Abbrev(p)
// if it isn't local acquistion
if (abbrev.GLADest != null){
var HLvalue = HLRange.getValue()
if (HLvalue !== 'X'){
GLAheader.push(abbrev)
GLAvalue.push(HLRange.getValue())
} else {
GLAheader.push(abbrev)
GLAvalue.push(2)
}
HLRange.clear()
}
}
if (acqRange2.isBlank() == false) {
HLRange2.clearFormat()
var p2 = acqRange2.getValue()
var abbrev2 = new Abbrev(p2)
// if it isn't local acquistion
if (abbrev2.GLADest != null){
var HLvalue2 = HLRange2.getValue()
if (HLvalue2 !== 'X'){
GLAheader.push(abbrev2)
GLAvalue.push(HLRange2.getValue())
} else {
GLAheader.push(abbrev2)
GLAvalue.push(2)
}
HLRange2.clear()
}
}
}
for(i=0; i<GLAheader.length;i++){
GLAsend(GLAheader[i], GLAvalue[i])
}
}
demo() {
var values = [['X', '3', '1', '2', 'X', '1']];
// Cell K3 - P3
var HLrange = this.sheet.getRange("K5:P5");
if (HLrange.isBlank() == false) {
var output = HtmlService
.createHtmlOutput('<input type="button" value="Restart" onclick="google.script.host.close()" />')
.setWidth(100)
.setHeight(50);
SpreadsheetApp.getUi().showModalDialog(output, 'Please clear the Harvest Line first!');
}
else {
HLrange.setValues(values).setBackground("red").setFontColor("red");
}
}
Reset() {
var sheet = this.sheet
var firstrowvalues = [[, , 12.0, , 6.0, , 18.0, , , , , , 0.0, 'Low', 5.0, 'Mid', 10.0, 'High', 15.0, 4.0, , , '2/4/6']]
var firstrow = sheet.getRange('A2:W2')
firstrow.setValues(firstrowvalues)
// globa value upper right
sheet.getRange('AB2').setValue('0')
// harvest line & acquired marker
sheet.getRange('A3:Y3').clearContent()
sheet.getRange('A5:Y6').clear()
sheet.getRange('A8:Y8').clearContent()
// clear general area.... not the input capacity or global capacity
sheet.getRange('E10:V14').clearContent()
// clear border in player's boxes
sheet.getRange('E10:G12').setBorder(false, false, false, false, null, null)
sheet.getRange('H10:J12').setBorder(false, false, false, false, null, null)
sheet.getRange('K10:M12').setBorder(false, false, false, false, null, null)
sheet.getRange('N10:P12').setBorder(false, false, false, false, null, null)
sheet.getRange('Q10:S12').setBorder(false, false, false, false, null, null)
sheet.getRange('T10:V12').setBorder(false, false, false, false, null, null)
// advancement
sheet.getRange('E15:V19').clearContent()
sheet.getRange('Y15:Y19').clearContent()
// change text in score marking ****DIFFERENT PER DIV*****
sheet.getRange(this.score).setValue('Low')
// high capacity met to 0
sheet.getRange('F47').setValue(0.0)
// GLA cells
sheet.getRange('Z21:AC22').clearContent()
sheet.getRange('Z21:AC22').setBorder(true, true, true, true, true, true)
sheet.getRange('Z25:AC26').clearContent()
sheet.getRange('Z25:AC26').setBorder(true, true, true, true, true, true)
// default message in message board
sheet.getRange('H20').setValue("MESSAGE BOARD")
sheet.getRange('H23').setValue("Greetings division, any pressing information about your society will show up here, stay tuned for news!")
// ****DIFFERENT PER DIV*****
this.demo()
}
MsgSend(titlerange, msgrange) {
var Central = ss.getSheetByName('Central')
var title = Central.getRange(titlerange).getValue()
var message = Central.getRange(msgrange).getValue()
this.titleboard.setValue(title)
this.msgboard.setValue(message)
}
// capacityrange = range on Capacity sheet for division
// capacitycolumn = column #s on capacity sheet for division
// scorecell = cell on Central sheet with score
// rowtoadd = 2 or 19, depending on if div is on upper or lower level on capacity sheet
newseason(capacityrange, capacitycolumn, scorecell, rowtoadd) {
// alert if capacity is empty (prevent accidental double click)
if (this.Actions.getValue() == ''){
SpreadsheetApp.getUi().alert('Please enter capacity!')
} else {
this.upCapacity(capacityrange, capacitycolumn, rowtoadd)
this.scorecheck(scorecell)
// update landcost
var landcostR = this.sheet.getRange('T2')
var landcost = +landcostR.getValue()
var newlandcostR = this.sheet.getRange('F45')
var newlandcost = +newlandcostR.getValue()
if (landcost !== newlandcost){
landcostR.setValue(newlandcost)
SpreadsheetApp.getUi().alert('Your landcost has changed from '+landcost+' to '+newlandcost)
}
// clear harvestline
var line = this.sheet.getRange('A5:Y6')
line.clear()
}
}
upCapacity(capacityrange, capacitycolumn, rowtoadd) {
// send capacity data to spreadsheet
var capacity = this.Capacity.getValue()
var row = CapacityTally(capacityrange, rowtoadd)
var cells = ss.getSheetByName('Capacity').getRange(row, capacitycolumn, "1", "2")
var values = [[this.Actions.getValue(),capacity]]
cells.setValues(values)
this.Actions.clearContent()
// hitting highest threshold increases capacity by one
var reserve = this.sheet.getRange("M2");
var highthreshold = this.sheet.getRange("S2").getValue()
if (reserve.getValue() >= highthreshold) {
var highcap = this.Highcap.getValue()
this.Capacity.setValue(capacity+1)
this.Highcap.setValue(highcap+1)
SpreadsheetApp.getUi().alert('Your capacity has changed from '+capacity+' to '+(capacity + +1)+'.')
}
}
// is the only way to up capacity to meet high threshold?
// if so, can I safely assume that Capacity will never meet the cap before victory point does?
// then i wont check capacity as a condition to reach next level
scorecheck(scorecell) {
var score = Central.getRange(scorecell).getValue()
var scoreindiv = this.sheet.getRange(this.score)
if (score !== scoreindiv.getValue()){
this.update(score)
scoreindiv.setValue(score)
}
}
update(score){
var thresholdrange = this.sheet.getRange('N2:S2')
var harvestrange = this.sheet.getRange('E2:H2')
var values = this.sheet.getRange('N52:S52').getValues()
var values2 = this.sheet.getRange('E52:H52').getValues()
var values3 = this.sheet.getRange('C52').getValues()
var capacity = this.Capacity.getValue()
if (capacity < values3){
var capacity = values3
this.Capacity.setValue(values3)
}
thresholdrange.setValues(values)
harvestrange.setValues(values2)
SpreadsheetApp.getUi().alert(
'Your score is now ' + score + '! Your capacity is now '+ capacity +
', with new values in Harvest Line, Extra Actions, and Reserve Thresholds!'
)
}
GLArequest() {
var GLArequests = this.sheet.getRange("Z21:AC22")
var reqval = GLArequests.getValues()
GLArequestsort(reqval, GLArequests, this.abbrev, this.sheet)
}
Generate() {
// Display a modal dialog box with custom HtmlService content.
var htmlOutput = HtmlService.createTemplateFromFile('HL prompt 3.html')
// using Force Print Scriptlet in html to print html. Inline template string.
var name = this.name
htmlOutput.selectedcode = '<option selected="selected" value="'+name+'">'+name+'</option>'
var html = htmlOutput.evaluate().setWidth(300).setHeight(150);
SpreadsheetApp.getUi().showModalDialog(html, 'Harvest Line Generator');
}
reserveok(){
var reserve = this.sheet.getRange("M2");
var reserveSum = reserve.getValue()
var reserveline = this.sheet.getRange("I2:L2")
var reservelineV = reserveline.getValues()
var newsum = +reservelineV[0][0] + +reservelineV[0][1] + +reservelineV[0][2] + +reservelineV[0][3]
reserve.setValue(+reserveSum + +newsum)
reserveline.clear().setBorder(true, true, true, true, true, true)
}
}
const East = new Division('East', 'E', 'Z9')
const West = new Division('West', 'W','Z17')
const South = new Division('South', 'S','Z13')
const North = new Division('North', 'N','Z5')
const Southeast = new Division('Southeast', 'SE','AB9')
const Northwest = new Division('Northwest', 'NW','AB17')
const Southwest = new Division('Southwest', 'SW','AB13')
const Northeast = new Division('Northeast', 'NE','AB5')
const Central = new Division('Central', null, null)
const Capacity = new Division('Capacity', null, null)
// -----------------------------------------------------------
class Abbrev {
constructor(abbreviation){
this.name = abbreviation
this.player = abbreviation.slice(0,1)
this.div = abbreviation.slice(1)
}
get division(){
switch (this.div){
case "N":
return "North";
break;
case "S":
return "South";
break;
case "E":
return "East";
break;
case "W":
return "West";
break;
case "NW":
return "Northwest";
break;
case "SE":
return "Southeast";
break;
case "NE":
return "Northeast";
break;
case "SW":
return "Southwest";
break;
default:
return null;
break;
}
}
get sheet(){
return eval(this.division)
}
// destination cell for GLA harvest from acquired reveal
get GLADest(){
var sheet = this.sheet
switch (this.player) {
case "1":
return sheet.getRange('G13')
break;
case "2":
return sheet.getRange('J13')
break;
case "3":
return sheet.getRange('M13')
break;
case "4":
return sheet.getRange('P13')
break;
case "5":
return sheet.getRange('S13')
break;
case "6":
return sheet.getRange('V13')
break;
default:
//local acquired instead of GLA
return null
break;
}
}
}