Skip to content

Commit 7932a8e

Browse files
SimonC4Cervator
authored andcommitted
Add fix for origin not being set correctly. Added shipBuilderOrigin as a new parameter to hullConfig to store the original origin value that was loaded from the file, whereas origin is the value that is used after it has been processed.
1 parent 129e0c9 commit 7932a8e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

main/src/com/miloshpetrov/sol2/files/HullConfigManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private HullConfig read(FileHandle hullConfigDirectory) {
123123
}
124124

125125
private void parseGunSlotList(JsonValue containerNode, HullConfig.Data configData) {
126-
Vector2 builderOrigin = shipBuilder.getOrigin(configData.internalName);
126+
Vector2 builderOrigin = new Vector2(configData.shipBuilderOrigin);
127127

128128
for(JsonValue gunSlotNode: containerNode) {
129129
Vector2 position = readVector2(gunSlotNode, "position", null);
@@ -161,6 +161,10 @@ private void readProperties(FileHandle propertiesFile, HullConfig.Data configDat
161161
configData.price = jsonNode.getInt("price", 0);
162162
configData.hirePrice = jsonNode.getFloat("hirePrice", 0);
163163

164+
Vector2 tmpV = new Vector2(jsonNode.get("rigidBody").get("origin").getFloat("x"),
165+
1 - jsonNode.get("rigidBody").get("origin").getFloat("y"));
166+
configData.shipBuilderOrigin.set(tmpV);
167+
164168
process(configData);
165169

166170
parseGunSlotList(jsonNode.get("gunSlots"), configData);
@@ -185,7 +189,7 @@ private AbilityConfig loadAbility(
185189
// Seems to offsets all positions by the shipbuilder origin
186190
// Todo: Find out what this function does and provide a better name.
187191
private void process(HullConfig.Data configData) {
188-
Vector2 builderOrigin = shipBuilder.getOrigin(configData.internalName);
192+
Vector2 builderOrigin = new Vector2(configData.shipBuilderOrigin);
189193

190194
configData.origin.set(builderOrigin)
191195
.scl(configData.size);

main/src/com/miloshpetrov/sol2/game/PathLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public Body getBodyAndSprite(SolGame game, HullConfig hullConfig, float scale, B
403403
fd.shape.dispose();
404404
}
405405

406-
orig = getOrigin(pathName, 1);
406+
orig = hullConfig.getShipBuilderOrigin();
407407
if (tex == null) {
408408
String imgName = pathName;
409409
tex = hullConfig.getTexture();

main/src/com/miloshpetrov/sol2/game/ship/hulls/HullConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public Vector2 getOrigin() {
104104
return new Vector2(data.origin);
105105
}
106106

107+
public Vector2 getShipBuilderOrigin() {
108+
return new Vector2(data.shipBuilderOrigin);
109+
}
110+
107111
private static List<Vector2> deepCopyOf(List<Vector2> src) {
108112
List<Vector2> returnList = new ArrayList<Vector2>(src.size());
109113

@@ -143,7 +147,10 @@ public final static class Data {
143147
public String displayName;
144148
public float price;
145149
public float hirePrice;
150+
// origin is the value after it has been processed
146151
public Vector2 origin = new Vector2();
152+
// shipBuilderOrigin is the vector loaded from the file
153+
public Vector2 shipBuilderOrigin = new Vector2();
147154

148155
public Data() {
149156

@@ -170,6 +177,7 @@ public Data(Data src) {
170177
this.price = src.price;
171178
this.hirePrice = src.hirePrice;
172179
this.origin = new Vector2(src.origin);
180+
this.shipBuilderOrigin = new Vector2(src.shipBuilderOrigin);
173181
this.gunSlots.addAll(src.gunSlots);
174182
}
175183

0 commit comments

Comments
 (0)