33
44package org .terasology .launcher .platform ;
55
6- import com .google .common .base .Objects ;
7- import com .google .common .collect .Sets ;
8-
9- import java .util .Locale ;
10- import java .util .Set ;
11-
126/**
137 * A simplified representation of a computer platform as `os` and `arch`
148 */
15- public final class Platform {
16-
17- final private OS os ;
18- final private Arch arch ;
19-
20- //TODO(skaldarnar): I'm not fully settled on how to model the Platform. I thought splitting this up into two enums
21- // for OS and Architecture would help with more type-safe construction of these values, simplify comparison to
22- // select the right JRE for a game, etc.
23- //
24- // On the other hand, the set of supported platforms is so limited, and continuing on a non-supported platform
25- // does not make much sense. So, maybe it is better to have a rather restrictive and explicit enum in the form of
26- // WINDOWS_X64
27- // LINUX_X64
28- // I'm adding the architecture to this list, as I hope that we'll be able to support old Intel and new M1 Macs at
29- // some point in the future, adding the following to the list:
30- // MAC_X64
31- // MAC_AARCH64
32- // The biggest drawback of being super-strict here is that development on non-supported platforms becomes
33- // impossible where it was just "not ideal" before.
34- public static final Set <Platform > SUPPORTED_PLATFORMS = Sets .newHashSet (
35- new Platform (OS .WINDOWS , Arch .X64 ),
36- new Platform (OS .LINUX , Arch .X64 ),
37- new Platform (OS .MAC , Arch .X64 )
38- );
9+ public enum Platform {
3910
40- public Platform (OS os , Arch arch ) {
41- this .os = os ;
42- this .arch = arch ;
43- }
11+ // unsupported platforms commented out, but might be useful for local development
12+ // MACOS_X64(OS.MAC, Arch.X64),
13+ // supported platforms by both the game and the launcher
14+ WINDOWS_X64 (OS .WINDOWS , Arch .X64 ),
15+ LINUX_X64 (OS .LINUX , Arch .X64 );
4416
4517 /**
46- * @return the simplified operating system name as platform os
18+ * The simplified operating system identifier.
4719 */
48- public String getOs () {
49- //TODO: change return type to OS
50- return os .name ().toLowerCase (Locale .ENGLISH );
51- }
52-
20+ public final OS os ;
5321 /**
54- * @return the simplified operating system architecture as platform arch
22+ * The simplified architecture identifier.
5523 */
56- public Arch getArch () {
57- return arch ;
24+ public final Arch arch ;
25+
26+ Platform (OS os , Arch arch ) {
27+ this .os = os ;
28+ this .arch = arch ;
5829 }
5930
6031 public boolean isLinux () {
@@ -73,23 +44,6 @@ public String toString() {
7344 return "OS '" + os + "', arch '" + arch + "'" ;
7445 }
7546
76- @ Override
77- public boolean equals (Object o ) {
78- if (this == o ) {
79- return true ;
80- }
81- if (o == null || getClass () != o .getClass ()) {
82- return false ;
83- }
84- Platform platform = (Platform ) o ;
85- return os == platform .os && arch == platform .arch ;
86- }
87-
88- @ Override
89- public int hashCode () {
90- return Objects .hashCode (os , arch );
91- }
92-
9347 /**
9448 * Get information on the host platform the launcher is currently running on.
9549 *
@@ -127,6 +81,23 @@ public static Platform getPlatform() throws UnsupportedPlatformException {
12781 throw new UnsupportedPlatformException ("Architecture not supported: " + platformArch );
12882 }
12983
130- return new Platform (os , arch );
84+ return fromOsAndArch (os , arch );
85+ }
86+
87+ /**
88+ * Derive the {@link Platform} from the given {@link OS} and {@link Arch}
89+ *
90+ * @throws UnsupportedPlatformException if the given OS and Arch combination is not supported
91+ */
92+ public static Platform fromOsAndArch (OS os , Arch arch ) throws UnsupportedPlatformException {
93+ if (os .equals (OS .WINDOWS ) && arch .equals (Arch .X64 )) {
94+ return WINDOWS_X64 ;
95+ } else if (os .equals (OS .LINUX ) && arch .equals (Arch .X64 )) {
96+ return LINUX_X64 ;
97+ // } else if (os.equals(OS.MAC) && arch.equals(Arch.X64)) {
98+ // return MACOS_X64;
99+ } else {
100+ throw new UnsupportedPlatformException ("Unsupported platform: " + os + " " + arch );
101+ }
131102 }
132103}
0 commit comments