diff options
Diffstat (limited to 'src/main/java/zajc/gogarchiver/api/GameDlc.java')
-rw-r--r-- | src/main/java/zajc/gogarchiver/api/GameDlc.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/zajc/gogarchiver/api/GameDlc.java b/src/main/java/zajc/gogarchiver/api/GameDlc.java new file mode 100644 index 0000000..91a08ac --- /dev/null +++ b/src/main/java/zajc/gogarchiver/api/GameDlc.java | |||
@@ -0,0 +1,69 @@ | |||
1 | //SPDX-License-Identifier: GPL-3.0 | ||
2 | /* | ||
3 | * gogarchiver-ng, an archival tool for GOG.com | ||
4 | * Copyright (C) 2024 Marko Zajc | ||
5 | * | ||
6 | * This program is free software: you can redistribute it and/or modify it under the | ||
7 | * terms of the GNU General Public License as published by the Free Software | ||
8 | * Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
12 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with this | ||
15 | * program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | package zajc.gogarchiver.api; | ||
18 | |||
19 | import java.util.Objects; | ||
20 | |||
21 | import javax.annotation.Nonnull; | ||
22 | |||
23 | import kong.unirest.json.*; | ||
24 | |||
25 | public class GameDlc extends Game { | ||
26 | |||
27 | @Nonnull private final Game parent; | ||
28 | |||
29 | private GameDlc(@Nonnull Game parent, @Nonnull String title, @Nonnull JSONObject downloads) { | ||
30 | super(parent.getUser(), parent.getId(), title, downloads, new JSONArray()); | ||
31 | |||
32 | this.parent = parent; | ||
33 | } | ||
34 | |||
35 | @Nonnull | ||
36 | @SuppressWarnings("null") | ||
37 | public static GameDlc fromJson(@Nonnull Game parent, @Nonnull JSONObject json) { | ||
38 | var title = json.getString("title"); | ||
39 | var downloads = json.getJSONArray("downloads").getJSONArray(0).getJSONObject(1); | ||
40 | |||
41 | return new GameDlc(parent, title, downloads); | ||
42 | } | ||
43 | |||
44 | @Nonnull | ||
45 | public Game getParent() { | ||
46 | return this.parent; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public int hashCode() { | ||
51 | final int prime = 31; | ||
52 | int result = super.hashCode(); | ||
53 | result = prime * result + Objects.hash(this.parent); | ||
54 | return result; | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public boolean equals(Object obj) { | ||
59 | if (this == obj) | ||
60 | return true; | ||
61 | else if (!super.equals(obj)) | ||
62 | return false; | ||
63 | else if (obj instanceof GameDlc other) | ||
64 | return Objects.equals(this.parent, other.parent); | ||
65 | else | ||
66 | return false; | ||
67 | } | ||
68 | |||
69 | } | ||