|
1 package org.hedgewars.mobile.EngineProtocol; |
|
2 |
|
3 import java.io.IOException; |
|
4 import java.io.OutputStream; |
|
5 import java.util.ArrayList; |
|
6 import java.util.UUID; |
|
7 |
|
8 import android.os.Parcel; |
|
9 import android.os.Parcelable; |
|
10 import android.util.Log; |
|
11 |
|
12 public class GameConfig implements Parcelable{ |
|
13 |
|
14 public GameMode mode = GameMode.MODE_LOCAL; |
|
15 public Map map = null; |
|
16 public String theme = null; |
|
17 public Scheme scheme = null; |
|
18 public Weapon weapon = null; |
|
19 |
|
20 public String mission = null; |
|
21 public String seed = null; |
|
22 |
|
23 public ArrayList<Team> teams = new ArrayList<Team>(8); |
|
24 |
|
25 public GameConfig(){ |
|
26 |
|
27 } |
|
28 |
|
29 public GameConfig(Parcel in){ |
|
30 readFromParcel(in); |
|
31 } |
|
32 |
|
33 |
|
34 |
|
35 public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
|
36 Log.d("HW_Frontend", "Sending Gameconfig..."); |
|
37 int teamCount = 8; |
|
38 epn.sendToEngine("TL"); //Write game mode |
|
39 if(mission != null) epn.sendToEngine(mission); |
|
40 |
|
41 //seed info |
|
42 epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString())); |
|
43 |
|
44 map.sendToEngine(epn); |
|
45 //dimensions of the map |
|
46 //templatefilter_command |
|
47 //mapgen_command |
|
48 //mazesize_command |
|
49 |
|
50 //epn.sendToEngine(String.format("etheme %s", theme)); |
|
51 |
|
52 //scheme.sendToEngine(epn); |
|
53 |
|
54 //weapon.sendToEngine(os, teamCount); |
|
55 |
|
56 for(Team t : teams){ |
|
57 //t.sendToEngine(os, teamCount, 50, 0); |
|
58 } |
|
59 |
|
60 |
|
61 } |
|
62 |
|
63 public int describeContents() { |
|
64 return 0; |
|
65 } |
|
66 |
|
67 public void writeToParcel(Parcel dest, int flags) { |
|
68 dest.writeString(mode.name()); |
|
69 dest.writeParcelable(map, flags); |
|
70 dest.writeString(theme); |
|
71 dest.writeParcelable(scheme, flags); |
|
72 dest.writeParcelable(weapon, flags); |
|
73 dest.writeString(mission); |
|
74 dest.writeString(seed); |
|
75 dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0); |
|
76 } |
|
77 |
|
78 private void readFromParcel(Parcel src){ |
|
79 mode = GameMode.valueOf(src.readString()); |
|
80 map = src.readParcelable(Map.class.getClassLoader()); |
|
81 theme = src.readString(); |
|
82 scheme = src.readParcelable(Scheme.class.getClassLoader()); |
|
83 weapon = src.readParcelable(Weapon.class.getClassLoader()); |
|
84 mission = src.readString(); |
|
85 seed = src.readString(); |
|
86 Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader()); |
|
87 for(Parcelable team : parcelables){ |
|
88 teams.add((Team)team); |
|
89 } |
|
90 |
|
91 } |
|
92 |
|
93 public static final Parcelable.Creator<GameConfig> CREATOR = new Parcelable.Creator<GameConfig>() { |
|
94 public GameConfig createFromParcel(Parcel source) { |
|
95 return new GameConfig(source); |
|
96 } |
|
97 public GameConfig[] newArray(int size) { |
|
98 return new GameConfig[size]; |
|
99 } |
|
100 }; |
|
101 |
|
102 } |