-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1CostRender.cs
More file actions
372 lines (343 loc) · 10.1 KB
/
Part1CostRender.cs
File metadata and controls
372 lines (343 loc) · 10.1 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
using BepInEx;
using BepInEx.Logging;
using DiskCardGame;
using UnityEngine;
using HarmonyLib;
using System.Collections.Generic;
using Art = RenderFixMaybe.Resources.costs;
namespace RenderFixMaybe
{
public class Part1CostRender
{
public static float Yposition = 0.85f;
public static float Xposition = 0.4f;
public static float pixelPerUnity = 100.0f;
public static Vector2 vector = new Vector2(Xposition, Yposition);
public static Sprite LoadSpriteFromResource(byte[] resourceFile)
{
var texture = new Texture2D(2, 2);
texture.LoadImage(resourceFile);
texture.filterMode = FilterMode.Point;
var sprite = UnityEngine.Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), vector, pixelPerUnity);
return sprite;
}
public static Sprite MakeSpriteFromTexture2D(Texture2D texture, bool flag)
{
Sprite sprite;
float Ytest = 0.85f;
float Xtest = 0.4f;
float ppu = 100.0f;
Vector2 vec = new Vector2(Xtest, Ytest);
if (flag)
{
Ytest = 0.85f;
Xtest = 0.4f;
vec = new Vector2(Xtest, Ytest);
sprite = UnityEngine.Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), vec, ppu);
}
else
{
Ytest = 0.0f;
Xtest = 1.0f;
vec = new Vector2(Xtest, Ytest);
sprite = UnityEngine.Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), vec, ppu);
}
return sprite;
}
public static Texture2D LoadTextureFromResource(byte[] resourceFile)
{
var texture = new Texture2D(2, 2);
texture.LoadImage(resourceFile);
texture.filterMode = FilterMode.Point;
return texture;
}
public static Texture2D CombineTextures(List<Texture2D> abilities, List<Vector2Int> patchlocations, byte[] resource)
{
bool flag = abilities != null;
Texture2D result;
if (flag)
{
Texture2D texture2D2 = LoadTextureFromResource(resource);
for (int j = 0; j < abilities.Count; j++)
{
int index = j;
texture2D2.SetPixels(patchlocations[index].x, patchlocations[index].y, abilities[index].width, abilities[index].height, abilities[index].GetPixels(), 0);
}
texture2D2.Apply();
result = texture2D2;
}
else
{
result = null;
}
return result;
}
public static Texture2D CombineMoxTextures(List<Texture2D> abilities, List<Vector2Int> patchlocations)
{
bool flag = abilities != null;
Texture2D result;
if (flag)
{
Texture2D texture2D2 = LoadTextureFromResource(Art.mox_cost_empty);
for (int j = 0; j < abilities.Count; j++)
{
int index = j;
texture2D2.SetPixels(patchlocations[index].x, patchlocations[index].y, abilities[index].width, abilities[index].height, abilities[index].GetPixels(), 0);
}
texture2D2.Apply();
result = texture2D2;
}
else
{
result = null;
}
return result;
}
public static List<Vector2Int> fourCost = new List<Vector2Int>
{
new Vector2Int(0, 0),
new Vector2Int(0, 28),
new Vector2Int(0, 56),
new Vector2Int(0, 84)
};
public static List<Vector2Int> threeCost = new List<Vector2Int>
{
new Vector2Int(0, 28),
new Vector2Int(0, 56),
new Vector2Int(0, 84)
};
public static List<Vector2Int> twoCost = new List<Vector2Int>
{
new Vector2Int(0, 56),
new Vector2Int(0, 84)
};
public static List<Vector2Int> oneCost = new List<Vector2Int>
{
new Vector2Int(0, 84)
};
public static Sprite Part1SpriteFinal(CardInfo card)
{
//Make the texture variables and set them to the default (which is 0)
Texture2D texBloodCost = LoadTextureFromResource(Art.blood_cost_0);
Texture2D texBoneCcost = LoadTextureFromResource(Art.bone_cost_0);
Texture2D texEnergyCost = LoadTextureFromResource(Art.energy_cost_0);
Texture2D textGemCost = LoadTextureFromResource(Art.mox_cost_empty);
//A list to hold the textures (important later, to combine them all)
List<Texture2D> list = new List<Texture2D>();
//Get the costs of blood, bone, and energy
int bloodCost = card.BloodCost;
int boneCost = card.BonesCost;
int energyCost = card.energyCost;
int moxCost = card.gemsCost.Count;
//Setting mox first
if (moxCost > 0)
{
//make a new list for the mox textures
List<Texture2D> gemCost = new List<Texture2D>();
//load up the mox textures as "empty"
Texture2D orange = LoadTextureFromResource(Art.mox_cost_e);
Texture2D blue = LoadTextureFromResource(Art.mox_cost_e);
Texture2D green = LoadTextureFromResource(Art.mox_cost_e);
List<Vector2Int> moxVector = new List<Vector2Int>
{
new Vector2Int(0, 0),
new Vector2Int(21, 0),
new Vector2Int(42, 0)
};
//If a card has a green mox, set the green mox
if (card.GemsCost.Contains(GemType.Green))
{
green = LoadTextureFromResource(Art.mox_cost_g);
}
//If a card has a green mox, set the Orange mox
if (card.GemsCost.Contains(GemType.Orange))
{
orange = LoadTextureFromResource(Art.mox_cost_o);
}
//If a card has a green mox, set the Blue mox
if (card.GemsCost.Contains(GemType.Blue))
{
blue = LoadTextureFromResource(Art.mox_cost_b);
}
//Add all moxes to the gemcost list
gemCost.Add(orange);
gemCost.Add(green);
gemCost.Add(blue);
//Combine the textures into one
Texture2D finalMoxTexture = CombineMoxTextures(gemCost, moxVector);
list.Add(finalMoxTexture);
}
//Switch Statement to set energy texture to the right cost, and add it to the list if it exists
switch (energyCost)
{
case 1:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_1);
list.Add(texEnergyCost);
break;
case 2:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_2);
list.Add(texEnergyCost);
break;
case 3:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_3);
list.Add(texEnergyCost);
break;
case 4:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_4);
list.Add(texEnergyCost);
break;
case 5:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_5);
list.Add(texEnergyCost);
break;
case 6:
texEnergyCost = LoadTextureFromResource(Art.energy_cost_6);
list.Add(texEnergyCost);
break;
}
//Switch statement to set the bone texture to the right cost
switch (boneCost)
{
case 1:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_1);
list.Add(texBoneCcost);
break;
case 2:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_2);
list.Add(texBoneCcost);
break;
case 3:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_3);
list.Add(texBoneCcost);
break;
case 4:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_4);
list.Add(texBoneCcost);
break;
case 5:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_5);
list.Add(texBoneCcost);
break;
case 6:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_6);
list.Add(texBoneCcost);
break;
case 7:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_7);
list.Add(texBoneCcost);
break;
case 8:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_8);
list.Add(texBoneCcost);
break;
case 9:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_9);
list.Add(texBoneCcost);
break;
case 10:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_10);
list.Add(texBoneCcost);
break;
case 11:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_11);
list.Add(texBoneCcost);
break;
case 12:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_12);
list.Add(texBoneCcost);
break;
case 13:
texBoneCcost = LoadTextureFromResource(Art.bone_cost_13);
list.Add(texBoneCcost);
break;
}
switch (bloodCost)
{
case 1:
texBloodCost = LoadTextureFromResource(Art.blood_cost_1);
list.Add(texBloodCost);
break;
case 2:
texBloodCost = LoadTextureFromResource(Art.blood_cost_2);
list.Add(texBloodCost);
break;
case 3:
texBloodCost = LoadTextureFromResource(Art.blood_cost_3);
list.Add(texBloodCost);
break;
case 4:
texBloodCost = LoadTextureFromResource(Art.blood_cost_4);
list.Add(texBloodCost);
break;
case 5:
texBloodCost = LoadTextureFromResource(Art.blood_cost_5);
list.Add(texBloodCost);
break;
case 6:
texBloodCost = LoadTextureFromResource(Art.blood_cost_6);
list.Add(texBloodCost);
break;
case 7:
texBloodCost = LoadTextureFromResource(Art.blood_cost_7);
list.Add(texBloodCost);
break;
case 8:
texBloodCost = LoadTextureFromResource(Art.blood_cost_8);
list.Add(texBloodCost);
break;
case 9:
texBloodCost = LoadTextureFromResource(Art.blood_cost_9);
list.Add(texBloodCost);
break;
case 10:
texBloodCost = LoadTextureFromResource(Art.blood_cost_10);
list.Add(texBloodCost);
break;
case 11:
texBloodCost = LoadTextureFromResource(Art.blood_cost_11);
list.Add(texBloodCost);
break;
case 12:
texBloodCost = LoadTextureFromResource(Art.blood_cost_12);
list.Add(texBloodCost);
break;
case 13:
texBloodCost = LoadTextureFromResource(Art.blood_cost_13);
list.Add(texBloodCost);
break;
}
//Make sure to use the right vector for the amount of items.
//So count the list and use a switch statement to pick the right one.
//If it is 0, just add them all to the list.
var counting = list.Count;
var total = new List<Vector2Int>();
switch (counting)
{
case 0:
list.Add(textGemCost);
list.Add(texEnergyCost);
list.Add(texBoneCcost);
list.Add(texBloodCost);
total = fourCost;
break;
case 1:
total = oneCost;
break;
case 2:
total = twoCost;
break;
case 3:
total = threeCost;
break;
case 4:
total = fourCost;
break;
}
//Combine all the textures from the list into one texture
Texture2D finalTexture = CombineTextures(list, total, Art.empty_cost);
//Convert the final texture to a sprite
Sprite finalSprite = MakeSpriteFromTexture2D(finalTexture, true);
return finalSprite;
}
}
}