This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
/
Card.cs
115 lines (99 loc) · 3.04 KB
/
Card.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
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using ANDREICSLIB;
using ANDREICSLIB.ClassExtras;
namespace MTGProxyMaker
{
public enum PrintModes
{
Minimal, BlackAndWhite, Colour
}
public enum SearchType
{
Name,MultiverseID
}
public class MinimalOptions
{
public bool Expansion;
public bool Rarity;
public bool Flavour;
}
public class CardHolder
{
public static string ImageFolder = "Images";
public Card C;
public Bitmap CardImage;
public CardHolder(Card c, int count)
{
C = c;
Count = count;
}
public int Count;
private static string GetImageFilename(Card c, PrintModes pm)
{
switch (pm)
{
case PrintModes.Minimal:
return Path.Combine(ImageFolder, c.ID.ToString() + ".min.jpg");
case PrintModes.BlackAndWhite:
return Path.Combine(ImageFolder, c.ID.ToString() + ".bw.jpg");
case PrintModes.Colour:
return Path.Combine(ImageFolder, c.ID.ToString() + ".col.jpg");
}
return null;
}
private void SetImage(PrintModes pm)
{
var fn = GetImageFilename(C, pm);
using (var i = (Bitmap)Image.FromFile(fn))
{
CardImage = new Bitmap(i);
}
}
public void GetAndSetImages(PrintModes pm, MinimalOptions mo)
{
//download first if necessary
//colour
var pathColour = GetImageFilename(C, PrintModes.Colour);
if (File.Exists(pathColour) == false)
NetExtras.DownloadFile(C.ImgURL, pathColour);
//black and white
var pathBw = GetImageFilename(C, PrintModes.BlackAndWhite);
if (File.Exists(pathBw) == false)
{
Bitmap bw;
using (var i = (Bitmap)Image.FromFile(pathColour))
{
bw = BitmapExtras.ApplyGrayscale(new Bitmap(i));
}
bw.Save(pathBw);
}
//minimal - always generate in case options have changed - todo - do properly
var minpath = GetImageFilename(C, PrintModes.Minimal);
if (File.Exists(minpath))
File.Delete(minpath);
var m = MinimalCardControl.Show(C, mo);
var min = new Bitmap(m.Width, m.Height);
m.DrawToBitmap(min, new Rectangle(0, 0, m.Width, m.Height));
min.Save(minpath);
SetImage(pm);
}
}
public class Card
{
public int? ID = null;
public string ImgURL;
public string Name;
public string Cost;
public string Types;
public string NewestExpansion;
public string Text;
public string FlavourText;
public string PT;
public string Rarity;
}
}