Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/caml_defaults_docs' into integra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
cam72cam committed Sep 12, 2023
2 parents acd50ff + 41ebfbe commit b193d6e
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 207 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cam72cam.immersiverailroading.registry;

import cam72cam.immersiverailroading.ImmersiveRailroading;
import cam72cam.immersiverailroading.entity.CarFreight;
import cam72cam.immersiverailroading.util.DataBlock;
import cam72cam.immersiverailroading.library.Gauge;
import cam72cam.immersiverailroading.library.GuiText;
import cam72cam.mod.resource.Identifier;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -22,19 +24,19 @@ public CarFreightDefinition(String defID, DataBlock data) throws Exception {
this(CarFreight.class, defID, data);
}

@Override
protected Identifier defaultDataLocation() {
return new Identifier(ImmersiveRailroading.MODID, "rolling_stock/default/freight.caml");
}

@Override
public void loadData(DataBlock data) throws Exception {
super.loadData(data);
DataBlock freight = data.getBlock("freight");
if (freight != null) {
this.numSlots = (int) Math.ceil(freight.getValue("slots").asInteger() * internal_inv_scale);
this.width = (int) Math.ceil(freight.getValue("width").asInteger() * internal_inv_scale);
this.validCargo = freight.getValues("cargo").stream().map(DataBlock.Value::asString).collect(Collectors.toList());
} else {
this.numSlots = 0;
this.width = 0;
this.validCargo = null;
}
this.numSlots = (int) Math.ceil(freight.getValue("slots").asInteger() * internal_inv_scale);
this.width = (int) Math.ceil(freight.getValue("width").asInteger() * internal_inv_scale);
List<DataBlock.Value> cargo = freight.getValues("cargo");
this.validCargo = cargo == null ? null : cargo.stream().map(DataBlock.Value::asString).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cam72cam.immersiverailroading.registry;

import cam72cam.immersiverailroading.ImmersiveRailroading;
import cam72cam.immersiverailroading.entity.CarPassenger;
import cam72cam.immersiverailroading.util.DataBlock;
import cam72cam.mod.resource.Identifier;

public class CarPassengerDefinition extends CarFreightDefinition {

Expand All @@ -10,8 +12,8 @@ public CarPassengerDefinition(String defID, DataBlock data) throws Exception {
}

@Override
public void loadData(DataBlock data) throws Exception {
super.loadData(data);
protected Identifier defaultDataLocation() {
return new Identifier(ImmersiveRailroading.MODID, "rolling_stock/default/passenger.caml");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cam72cam.immersiverailroading.model.StockModel;
import cam72cam.immersiverailroading.util.FluidQuantity;
import cam72cam.mod.fluid.Fluid;
import cam72cam.mod.resource.Identifier;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,6 +27,11 @@ public CarTankDefinition(String defID, DataBlock data) throws Exception {
super(type, defID, data);
}

@Override
protected Identifier defaultDataLocation() {
return new Identifier(ImmersiveRailroading.MODID, "rolling_stock/default/tank.caml");
}

@Override
public void loadData(DataBlock data) throws Exception {
super.loadData(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@
import cam72cam.immersiverailroading.entity.EntityBuildableRollingStock;
import cam72cam.immersiverailroading.entity.EntityCoupleableRollingStock.CouplerType;
import cam72cam.immersiverailroading.entity.EntityRollingStock;
import cam72cam.immersiverailroading.util.CAML;
import cam72cam.immersiverailroading.util.DataBlock;
import cam72cam.immersiverailroading.util.*;
import cam72cam.immersiverailroading.gui.overlay.GuiBuilder;
import cam72cam.immersiverailroading.gui.overlay.Readouts;
import cam72cam.immersiverailroading.library.*;
import cam72cam.immersiverailroading.model.StockModel;
import cam72cam.immersiverailroading.model.components.ModelComponent;
import cam72cam.immersiverailroading.util.JSON;
import cam72cam.immersiverailroading.util.RealBB;
import cam72cam.mod.ModCore;
import cam72cam.mod.entity.EntityRegistry;
import cam72cam.mod.math.Vec3d;
import cam72cam.mod.model.obj.OBJGroup;
import cam72cam.mod.model.obj.VertexBuffer;
import cam72cam.mod.resource.Identifier;
import cam72cam.mod.serialization.ResourceCache;
import cam72cam.mod.serialization.*;
import cam72cam.mod.serialization.ResourceCache.GenericByteBuffer;
import cam72cam.mod.serialization.TagCompound;
import cam72cam.mod.serialization.TagField;
import cam72cam.mod.serialization.TagMapped;
import cam72cam.mod.text.TextUtil;
import cam72cam.mod.world.World;

import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
Expand All @@ -44,6 +40,7 @@ public abstract class EntityRollingStockDefinition {

public final String defID;
private final Class<? extends EntityRollingStock> type;

public final List<String> itemGroups;
public Map<String, String> textureNames;
public float dampeningAmount;
Expand Down Expand Up @@ -132,7 +129,7 @@ public SoundDefinition(DataBlock obj) {
volume = obj.getValue("volume").asFloat(1.0f);
}

public static SoundDefinition getOrDefault(DataBlock block, String key, SoundDefinition fallback) {
public static SoundDefinition getOrDefault(DataBlock block, String key) {
DataBlock found = block.getBlock(key);
if (found != null) {
return new SoundDefinition(found);
Expand All @@ -141,7 +138,7 @@ public static SoundDefinition getOrDefault(DataBlock block, String key, SoundDef
if (ident != null && ident.canLoad()) {
return new SoundDefinition(ident);
}
return fallback;
return null;
}
}

Expand Down Expand Up @@ -175,7 +172,7 @@ public AnimationDefinition(DataBlock obj) {
offset = obj.getValue("offset").asFloat(0f);
invert = obj.getValue("invert").asBoolean(false);
frames_per_tick = obj.getValue("frames_per_tick").asFloat(1f);
sound = SoundDefinition.getOrDefault(obj, "sound", null);
sound = SoundDefinition.getOrDefault(obj, "sound");
}

public boolean valid() {
Expand Down Expand Up @@ -229,7 +226,7 @@ public EntityRollingStockDefinition(Class<? extends EntityRollingStock> type, St
this.defID = defID;


loadData(data);
loadData(transformData(data));

this.model = createModel();
this.itemGroups = model.groups.keySet().stream().filter(x -> !ModelComponentType.shouldRender(x)).collect(Collectors.toList());
Expand Down Expand Up @@ -292,11 +289,33 @@ public boolean shouldScalePitch() {
return ConfigSound.scaleSoundToGauge && scalePitch;
}

protected Identifier defaultDataLocation() {
return new Identifier(ImmersiveRailroading.MODID, "rolling_stock/default/base.caml");
}

private DataBlock withImports(DataBlock data) throws IOException {
List<DataBlock.Value> imports = data.getValues("import");
if (imports != null) {
for (DataBlock.Value toImport : imports) {
DataBlock loaded = DataBlock.load(toImport.asIdentifier());
loaded = withImports(loaded);
// Graft data on TOP of loaded
data = new MergedBlocks(loaded, data);
}
}
return data;
}

private DataBlock transformData(DataBlock data) throws IOException {
DataBlock base = DataBlock.load(defaultDataLocation());
return new MergedBlocks(withImports(base), withImports(data));
}

public void loadData(DataBlock data) throws Exception {
name = data.getValue("name").asString();
modelerName = data.getValue("modeler").asString("N/A");
packName = data.getValue("pack").asString("N/A");
darken = data.getValue("darken_model").asFloat(0f);
modelerName = data.getValue("modeler").asString();
packName = data.getValue("pack").asString();
darken = data.getValue("darken_model").asFloat();
internal_model_scale = 1;
internal_inv_scale = 1;
// TODO Gauge.from(Gauge.STANDARD).value() what happens when != Gauge.STANDARD
Expand All @@ -315,7 +334,7 @@ public void loadData(DataBlock data) throws Exception {
}

textureNames = new LinkedHashMap<>();
textureNames.put("", "Default");
//textureNames.put("", "Default");
DataBlock tex_variants = data.getBlock("tex_variants");
if (tex_variants != null) {
tex_variants.getValueMap().forEach((key, value) -> textureNames.put(value.asString(), key));
Expand Down Expand Up @@ -358,75 +377,61 @@ public void loadData(DataBlock data) throws Exception {
bogeyFront = pivot.getValue("front").asFloat() * (float) internal_model_scale;
bogeyRear = pivot.getValue("rear").asFloat() * (float) internal_model_scale;

dampeningAmount = data.getValue("sound_dampening_percentage").asFloat(0.75f);
dampeningAmount = data.getValue("sound_dampening_percentage").asFloat();
if (dampeningAmount < 0 || dampeningAmount > 1) {
dampeningAmount = 0.75f;
}
scalePitch = data.getValue("scale_pitch").asBoolean(true);

couplerSlackFront = couplerSlackRear = 0.025f;
scalePitch = data.getValue("scale_pitch").asBoolean();

DataBlock couplers = data.getBlock("couplers");
if (couplers != null) {
couplerOffsetFront = couplers.getValue("front_offset").asFloat(0f) * (float) internal_model_scale;
couplerOffsetRear = couplers.getValue("rear_offset").asFloat(0f) * (float) internal_model_scale;
couplerSlackFront = couplers.getValue("front_slack").asFloat(couplerSlackFront) * (float) internal_model_scale;
couplerSlackRear = couplers.getValue("rear_slack").asFloat(couplerSlackRear) * (float) internal_model_scale;
}
couplerOffsetFront = couplers.getValue("front_offset").asFloat() * (float) internal_model_scale;
couplerOffsetRear = couplers.getValue("rear_offset").asFloat() * (float) internal_model_scale;
couplerSlackFront = couplers.getValue("front_slack").asFloat() * (float) internal_model_scale;
couplerSlackRear = couplers.getValue("rear_slack").asFloat() * (float) internal_model_scale;

DataBlock properties = data.getBlock("properties");
weight = (int) Math.ceil(properties.getValue("weight_kg").asInteger() * internal_inv_scale);
valveGear = ValveGearConfig.get(properties, "valve_gear");
hasIndependentBrake = properties.getValue("independent_brake").asBoolean(independentBrakeDefault());
hasPressureBrake = properties.getValue("pressure_brake").asBoolean(pressureBrakeDefault());
hasIndependentBrake = properties.getValue("independent_brake").asBoolean();
hasPressureBrake = properties.getValue("pressure_brake").asBoolean();
// Locomotives default to linear brake control
isLinearBrakeControl = properties.getValue("linear_brake_control").asBoolean(!(this instanceof LocomotiveDefinition));
isLinearBrakeControl = properties.getValue("linear_brake_control").asBoolean();

brakeCoefficient = PhysicalMaterials.STEEL.kineticFriction(PhysicalMaterials.CAST_IRON);
try {
brakeCoefficient = PhysicalMaterials.STEEL.kineticFriction(PhysicalMaterials.valueOf(properties.getValue("brake_shoe_material").asString("CAST_IRON")));
brakeCoefficient = PhysicalMaterials.STEEL.kineticFriction(PhysicalMaterials.valueOf(properties.getValue("brake_shoe_material").asString()));
} catch (Exception ex) {
ImmersiveRailroading.warn("Invalid brake_shoe_material, possible values are: %s", Arrays.toString(PhysicalMaterials.values()));
}
brakeCoefficient = properties.getValue("brake_friction_coefficient").asFloat(brakeCoefficient);
// https://en.wikipedia.org/wiki/Rolling_resistance#Rolling_resistance_coefficient_examples
rollingResistanceCoefficient = properties.getValue("rolling_resistance_coefficient").asDouble(0.002);
directFrictionCoefficient = properties.getValue("direct_friction_coefficient").asDouble(0);
rollingResistanceCoefficient = properties.getValue("rolling_resistance_coefficient").asDouble();
directFrictionCoefficient = properties.getValue("direct_friction_coefficient").asDouble();

swayMultiplier = properties.getValue("swayMultiplier").asDouble(1);
tiltMultiplier = properties.getValue("tiltMultiplier").asDouble(0);
swayMultiplier = properties.getValue("swayMultiplier").asDouble();
tiltMultiplier = properties.getValue("tiltMultiplier").asDouble();

interiorLightLevel = properties.getValue("interior_light_level").asFloat(6 / 15f);
hasInternalLighting = properties.getValue("internalLighting").asBoolean(this instanceof CarPassengerDefinition || this instanceof LocomotiveDefinition);
interiorLightLevel = properties.getValue("interior_light_level").asFloat();
hasInternalLighting = properties.getValue("internalLighting").asBoolean();

DataBlock lights = data.getBlock("lights");
if (lights != null) {
lights.getBlockMap().forEach((key, block) -> this.lights.put(key, new LightDefinition(block)));
}

wheel_sound = new Identifier(ImmersiveRailroading.MODID, "sounds/default/track_wheels.ogg");
clackFront = clackRear = new Identifier(ImmersiveRailroading.MODID, "sounds/default/clack.ogg");
couple_sound = new Identifier(ImmersiveRailroading.MODID, "sounds/default/coupling.ogg");
sliding_sound = new Identifier(ImmersiveRailroading.MODID, "sounds/default/sliding.ogg");
flange_sound = new Identifier(ImmersiveRailroading.MODID, "sounds/default/flange.ogg");
flange_min_yaw = 2.5;
collision_sound = new Identifier(ImmersiveRailroading.MODID, "sounds/default/collision.ogg");

DataBlock sounds = data.getBlock("sounds");
if (sounds != null) {
wheel_sound = sounds.getValue("wheels").asIdentifier(wheel_sound);
clackFront = clackRear = sounds.getValue("clack").asIdentifier(clackFront);
clackFront = sounds.getValue("clack_front").asIdentifier(clackFront);
clackRear = sounds.getValue("clack_rear").asIdentifier(clackRear);
couple_sound = sounds.getValue("couple").asIdentifier(couple_sound);
sliding_sound = sounds.getValue("sliding").asIdentifier(sliding_sound);
flange_sound = sounds.getValue("flange").asIdentifier(flange_sound);
flange_min_yaw = sounds.getValue("flange_min_yaw").asDouble(flange_min_yaw);
collision_sound = sounds.getValue("collision").asIdentifier(collision_sound);
DataBlock controls = sounds.getBlock("controls");
if (controls != null) {
controls.getBlockMap().forEach((key, block) -> controlSounds.put(key, new ControlSoundsDefinition(block)));
}
wheel_sound = sounds.getValue("wheels").asIdentifier();
clackFront = clackRear = sounds.getValue("clack").asIdentifier();
clackFront = sounds.getValue("clack_front").asIdentifier(clackFront);
clackRear = sounds.getValue("clack_rear").asIdentifier(clackRear);
couple_sound = sounds.getValue("couple").asIdentifier();
sliding_sound = sounds.getValue("sliding").asIdentifier();
flange_sound = sounds.getValue("flange").asIdentifier();
flange_min_yaw = sounds.getValue("flange_min_yaw").asDouble();
collision_sound = sounds.getValue("collision").asIdentifier();
DataBlock soundControls = sounds.getBlock("controls");
if (soundControls != null) {
soundControls.getBlockMap().forEach((key, block) -> controlSounds.put(key, new ControlSoundsDefinition(block)));
}

Identifier overlay = data.getValue("overlay").asIdentifier();
Expand Down Expand Up @@ -785,15 +790,6 @@ public float interiorLightLevel() {
return interiorLightLevel;
}


protected boolean independentBrakeDefault() {
return false;
}

protected boolean pressureBrakeDefault() {
return true;
}

public boolean isLinearBrakeControl() {
return isLinearBrakeControl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class FreightDefinition extends EntityRollingStockDefinition {

public void loadData(DataBlock data) throws Exception {
super.loadData(data);
this.showCurrentLoadOnly = data.getValue("show_current_load_only").asBoolean(false);
this.showCurrentLoadOnly = data.getValue("show_current_load_only").asBoolean();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ protected GuiBuilder getDefaultOverlay(DataBlock data) throws IOException {
}

@Override
protected boolean multiUnitDefault() {
return false;
}

@Override
protected boolean pressureBrakeDefault() {
return false;
protected Identifier defaultDataLocation() {
return new Identifier(ImmersiveRailroading.MODID, "rolling_stock/default/handcar.caml");
}
}
Loading

0 comments on commit b193d6e

Please sign in to comment.