Skip to content

Commit

Permalink
schemaClip, removed base(remake of MovingBlocks#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrijaned committed Nov 23, 2018
1 parent 5bdd002 commit 142bd1b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
package org.destinationsol.files;

import com.badlogic.gdx.math.Vector2;
import org.destinationsol.assets.json.Validator;
import org.json.JSONArray;
import org.json.JSONObject;
import com.badlogic.gdx.utils.SerializationException;
import org.destinationsol.assets.Assets;
import org.destinationsol.assets.json.Json;
import org.destinationsol.common.SolException;
import org.destinationsol.assets.json.Validator;
import org.destinationsol.common.SolMath;
import org.destinationsol.game.AbilityCommonConfigs;
import org.destinationsol.game.item.Engine;
Expand All @@ -36,9 +32,10 @@
import org.destinationsol.game.ship.UnShield;
import org.destinationsol.game.ship.hulls.GunSlot;
import org.destinationsol.game.ship.hulls.HullConfig;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -163,7 +160,6 @@ private void readProperties(JSONObject rootNode, HullConfig.Data configData) {
configData.maxLife = rootNode.getInt("maxLife");

configData.lightSrcPoss = SolMath.readV2List(rootNode, "lightSrcPoss");
configData.hasBase = rootNode.optBoolean("hasBase");
configData.forceBeaconPoss = SolMath.readV2List(rootNode, "forceBeaconPoss");
configData.doorPoss = SolMath.readV2List(rootNode, "doorPoss");
configData.type = HullConfig.Type.forName(rootNode.optString("type"));
Expand All @@ -172,7 +168,7 @@ private void readProperties(JSONObject rootNode, HullConfig.Data configData) {
configData.ability = loadAbility(rootNode, itemManager, abilityCommonConfigs);

configData.displayName = rootNode.optString("displayName", "---");
configData.price = rootNode.optInt("price", 0);
configData.price = (float) rootNode.optDouble("price", 0);
configData.hirePrice = (float) rootNode.optDouble("hirePrice", 0);

Vector2 tmpV = new Vector2((float) rootNode.getJSONObject("rigidBody").getJSONObject("origin").getDouble("x"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,6 @@ public ShipBuilder() {
myCollisionMeshLoader = new CollisionMeshLoader();
}

private static Fixture getBase(boolean hasBase, Body body) {
if (!hasBase) {
return null;
}
Fixture base = null;
Vector2 v = SolMath.getVec();
float lowestX = Float.MAX_VALUE;
for (Fixture f : body.getFixtureList()) {
Shape s = f.getShape();
if (!(s instanceof PolygonShape)) {
continue;
}
PolygonShape poly = (PolygonShape) s;
int pointCount = poly.getVertexCount();
for (int i = 0; i < pointCount; i++) {
poly.getVertex(i, v);
if (v.x < lowestX) {
base = f;
lowestX = v.x;
}
}
}
SolMath.free(v);
return base;
}

public FarShip buildNewFar(SolGame game, Vector2 position, Vector2 speed, float angle, float rotationSpeed, Pilot pilot,
String items, HullConfig hullConfig,
RemoveController removeController,
Expand Down Expand Up @@ -305,8 +279,7 @@ private Hull buildHull(SolGame game, Vector2 position, Vector2 speed, float angl
doors.add(door);
}

Fixture base = getBase(hullConfig.hasBase(), body);
Hull hull = new Hull(game, hullConfig, body, gunMount0, gunMount1, base, lCs, life, beacons, doors, shieldFixture);
Hull hull = new Hull(game, hullConfig, body, gunMount0, gunMount1, lCs, life, beacons, doors, shieldFixture);
body.setLinearVelocity(speed);
body.setAngularVelocity(rotationSpeed * MathUtils.degRad);
return hull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Fixture;
import org.destinationsol.assets.audio.OggSoundManager;
import org.destinationsol.assets.audio.SpecialSounds;
import org.destinationsol.common.SolMath;
Expand Down Expand Up @@ -135,11 +134,8 @@ public void handleContact(SolObject other, float absImpulse,
return;
}
if (myHull.config.getType() != HullConfig.Type.STATION) {
Fixture f = null; // restore?
float dmg = absImpulse / myHull.getMass() / myHull.config.getDurability();
if (f == myHull.getBase()) {
dmg *= BASE_DUR_MOD;
}
dmg *= BASE_DUR_MOD;
receiveDmg((int) dmg, game, collPos, DmgType.CRASH);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class Hull {
private final Body body;
private final GunMount gunMount1;
private final GunMount gunMount2;
private final Fixture base;
private final List<LightSource> lightSources;
private final Vector2 position;
private final Vector2 speed;
Expand All @@ -62,14 +61,13 @@ public class Hull {
private ShipEngine engine;
private List<DSParticleEmitter> particleEmitters;

public Hull(SolGame game, HullConfig hullConfig, Body body, GunMount gunMount1, GunMount gunMount2, Fixture base,
public Hull(SolGame game, HullConfig hullConfig, Body body, GunMount gunMount1, GunMount gunMount2,
List<LightSource> lightSources, float life, ArrayList<ForceBeacon> forceBeacons,
ArrayList<Door> doors, Fixture shieldFixture) {
config = hullConfig;
this.body = body;
this.gunMount1 = gunMount1;
this.gunMount2 = gunMount2;
this.base = base;
this.lightSources = lightSources;
this.life = life;
this.doors = doors;
Expand All @@ -90,10 +88,6 @@ public Body getBody() {
return body;
}

public Fixture getBase() {
return base;
}

public GunMount getGunMount(boolean second) {
return second ? gunMount2 : gunMount1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public float getDurability() {
return data.durability;
}

public boolean hasBase() {
return data.hasBase;
}

public List<Vector2> getForceBeaconPositions() {
return deepCopyOf(data.forceBeaconPoss);
}
Expand Down Expand Up @@ -166,7 +162,6 @@ public final static class Data {
public List<DSParticleEmitter> particleEmitters = new ArrayList<>();
public List<Vector2> lightSrcPoss = new ArrayList<>();
public float durability;
public boolean hasBase;
public List<Vector2> forceBeaconPoss = new ArrayList<>();
public List<Vector2> doorPoss = new ArrayList<>();
public TextureAtlas.AtlasRegion icon;
Expand All @@ -193,7 +188,6 @@ public Data(Data src) {
this.maxLife = src.maxLife;
this.lightSrcPoss = deepCopyOf(src.lightSrcPoss);
this.durability = src.durability;
this.hasBase = src.hasBase;
this.forceBeaconPoss = deepCopyOf(src.forceBeaconPoss);
this.doorPoss = deepCopyOf(src.doorPoss);
this.icon = new TextureAtlas.AtlasRegion(src.icon);
Expand Down
68 changes: 68 additions & 0 deletions engine/src/main/resources/assets/schemas/schemaClip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Clips are the ITEMS loaded into guns. They specify things like buying price, display name...",
"type": "object",
"required": [
"projectile",
"size"
],
"properties": {
"projectile": {
"description": "name of the projectile shot by this clip, defined in projectilesConfig",
"type": "string",
"pattern": "^\\w+$"
},
"infinite": {
"type": "boolean",
"description": "True if it never runs out, false otherwise. When false, several new fields are required"
},
"size": {
"type": "integer",
"exclusiveMinimum": 0,
"description": "Amount of projectiles in the clip"
},
"projectilesPerShot": {
"type": "integer",
"minimum": 1,
"description": "Amount of projectiles consumed per shot"
}
},
"anyOf": [
{
"properties": {
"infinite": {
"enum": [
true
]
}
},
"required": ["infinite"]
},
{
"properties": {
"infinite": {
"enum": [
false
]
},
"price": {
"type": "integer",
"description": "Buying price of the clip"
},
"displayName": {
"type": "string",
"description": "Name of the clip"
},
"plural": {
"type": "string",
"description": "Plural form of 'displayName'"
}
},
"required": [
"price",
"displayName",
"plural"
]
}
]
}

0 comments on commit 142bd1b

Please sign in to comment.