Client work of the Week #4

Merged
fkoppe merged 29 commits from dev/client into development 2024-11-17 12:24:46 +01:00
8 changed files with 199 additions and 53 deletions
Showing only changes of commit 206c0d543e - Show all commits

View File

@@ -1,18 +1,17 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" <configuration default="false" name="MdgaApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true">
nameIsGenerated="true"> <option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp" />
<option name="MAIN_CLASS_NAME" value="pp.mdga.client.MdgaApp"/> <module name="Projekte.mdga.client.main" />
<module name="Projekte.mdga.client.main"/> <option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties" />
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/> <option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="pp.mdga.client.*"/> <option name="PATTERN" value="pp.mdga.client.Board.*" />
<option name="ENABLED" value="true"/> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>
<method v="2"> <method v="2">
<option name="Make" enabled="true"/> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
</component> </component>

View File

@@ -1,4 +1,4 @@
package pp.mdga.client; package pp.mdga.client.Board;
public enum Asset { public enum Asset {
bigTent, bigTent,
@@ -8,13 +8,13 @@ public enum Asset {
jet, jet,
lw, lw,
marine, marine,
node_home_blue("./node_home/node_home.j3o", "./node_home/node_home_blue.png"), node_home_blue("./node_home/node_home.j3o", "./node_home/node_home_blue_diff.png"),
node_home_black("./node_home/node_home.j3o", "./node_home/node_home_black.png"), node_home_black("./node_home/node_home.j3o", "./node_home/node_home_black_diff.png"),
node_home_green("./node_home/node_home.j3o", "./node_home/node_home_green.png"), node_home_green("./node_home/node_home.j3o", "./node_home/node_home_green_diff.png"),
node_home_yellow("./node_home/node_home.j3o", "./node_home/node_home_yellow.png"), node_home_yellow("./node_home/node_home.j3o", "./node_home/node_home_yellow_diff.png"),
node_normal, node_normal,
node_start("./node_normal/node_normal.j3o", "./node_normal/node_normal_start.png"), node_start("./node_normal/node_normal.j3o", "./node_normal/node_start_diff.png"),
node_bonus("./node_normal/node_normal.j3o", "./node_normal/node_normal_bonus.png"), node_bonus("./node_normal/node_normal.j3o", "./node_normal/node_bonus_diff.png"),
radar, radar,
shieldCard, shieldCard,
ship, ship,
@@ -22,7 +22,7 @@ public enum Asset {
swapCard, swapCard,
tank, tank,
turboCard, turboCard,
world(1.1f); world(1.2f);
private final String modelPath; private final String modelPath;
private final String diffPath; private final String diffPath;

View File

@@ -0,0 +1,3 @@
package pp.mdga.client.Board;
public record AssetOnMap(Asset asset, int x, int y){}

View File

@@ -1,13 +1,21 @@
package pp.mdga.client.Board; package pp.mdga.client.Board;
import com.jme3.material.Material;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Spatial;
import pp.mdga.client.MdgaApp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class BoardView { public class BoardView {
private static final float GRID_SIZE = 10.0f; private static final float GRID_SIZE = 1.72f;
private static final float GRID_ELEVATION = 0.0f; private static final float GRID_ELEVATION = 0.0f;
private static final int GRID_EXTEND = 5; private static final int GRID_EXTEND = 5;
private static final String MAP_NAME = "map.mdga";
private final MdgaApp mdgaApp;
private PileControl drawPile = new PileControl(); private PileControl drawPile = new PileControl();
private PileControl discardPile = new PileControl(); private PileControl discardPile = new PileControl();
@@ -15,16 +23,47 @@ public class BoardView {
private ArrayList<NodeControl> infield = new ArrayList<NodeControl>(40); private ArrayList<NodeControl> infield = new ArrayList<NodeControl>(40);
private ArrayList<PieceControl> pieces; private ArrayList<PieceControl> pieces;
BoardView(int playerCount) { public BoardView(int playerCount, MdgaApp mdgaApp) {
assert(2 <= playerCount && playerCount <= 4); assert(2 <= playerCount && playerCount <= 4);
assert(mdgaApp != null);
this.mdgaApp = mdgaApp;
pieces = new ArrayList<PieceControl>(4 * playerCount); pieces = new ArrayList<PieceControl>(4 * playerCount);
initMap();
}
private void initMap() {
List<AssetOnMap> assetOnMaps = new MapLoader().loadMap(MAP_NAME);
for (AssetOnMap assetOnMap : assetOnMaps){
int x = assetOnMap.x();
int y = assetOnMap.y();
Spatial model = createModel(assetOnMap.asset());
model.setLocalTranslation(gridToWorld(x,y));
}
}
private Spatial createModel(Asset asset){
String modelName = asset.getModelPath();
String texName = asset.getDiffPath();
Spatial model = mdgaApp.getAssetManager().loadModel(modelName);
model.scale(asset.getSize());
model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90));
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
Material mat = new Material(mdgaApp.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", mdgaApp.getAssetManager().loadTexture(texName));
model.setMaterial(mat);
mdgaApp.getRootNode().attachChild(model);
return model;
} }
private static Vector3f gridToWorld(int x, int y) { private static Vector3f gridToWorld(int x, int y) {
assert(-GRID_EXTEND <= x && x <= GRID_EXTEND); assert(-GRID_EXTEND <= x && x <= GRID_EXTEND);
assert(-GRID_EXTEND <= y && y < GRID_EXTEND); assert(-GRID_EXTEND <= y && y < GRID_EXTEND);
return new Vector3f(GRID_SIZE * x, GRID_ELEVATION, GRID_SIZE * y); return new Vector3f(GRID_SIZE * x, GRID_SIZE * y, GRID_ELEVATION);
} }
} }

View File

@@ -0,0 +1,65 @@
package pp.mdga.client.Board;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class MapLoader {
public MapLoader(){
}
public List<AssetOnMap> loadMap(String mapName) {
List<AssetOnMap> assetsOnMap = new ArrayList<>();
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mapName);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
while (true) {
String entry = reader.readLine();
if(entry == null) break;
entry = entry.trim();
if(entry.isEmpty()) continue;
if(entry.charAt(0) == '#') continue;
String[] parts = entry.trim().split(" ");
assert(parts.length == 2);
String assetName = parts[0];
String[] coordinates = parts[1].split(",");
assert(coordinates.length == 2);
int x = Integer.parseInt(coordinates[0]);
int y = Integer.parseInt(coordinates[1]);
Asset asset = getLoadedAsset(assetName);
assetsOnMap.add(new AssetOnMap(asset, x, y));
}
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return assetsOnMap;
}
private Asset getLoadedAsset(String assetName) {
return switch(assetName){
case "node" -> Asset.node_normal;
case "node_start" -> Asset.node_start;
case "node_bonus" -> Asset.node_bonus;
case "node_home_blue" -> Asset.node_home_blue;
case "node_home_yellow" -> Asset.node_home_yellow;
case "node_home_black" -> Asset.node_home_black;
case "node_home_green" -> Asset.node_home_green;
case "world" -> Asset.world;
default -> throw new IllegalStateException("Unexpected value: " + assetName);
};
}
}

View File

@@ -1,21 +1,26 @@
package pp.mdga.client; package pp.mdga.client;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import pp.mdga.client.Animation.AnimationHandler; import pp.mdga.client.Animation.AnimationHandler;
import com.jme3.light.AmbientLight; import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.shadow.DirectionalLightShadowRenderer; import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import pp.mdga.client.Board.Asset;
import pp.mdga.client.Board.AssetOnMap;
import pp.mdga.client.Board.BoardView;
import pp.mdga.client.Board.MapLoader;
import java.util.List;
public class MdgaApp extends SimpleApplication { public class MdgaApp extends SimpleApplication {
private AnimationHandler animationHandler; private AnimationHandler animationHandler;
private BoardView boardView;
public static void main(String[] args) { public static void main(String[] args) {
MdgaApp app = new MdgaApp(); MdgaApp app = new MdgaApp();
@@ -32,6 +37,7 @@ public static void main(String[] args) {
@Override @Override
public void simpleInitApp() { public void simpleInitApp() {
animationHandler = new AnimationHandler(this); animationHandler = new AnimationHandler(this);
boardView = new BoardView(4,this);
flyCam.setEnabled(true); flyCam.setEnabled(true);
int zoom = 20; int zoom = 20;
@@ -51,37 +57,7 @@ public void simpleInitApp() {
dlsr.setLight(sun); dlsr.setLight(sun);
viewPort.addProcessor(dlsr); viewPort.addProcessor(dlsr);
createModel(Asset.lw).setLocalTranslation(new Vector3f(0,-10,0));
createModel(Asset.cir).setLocalTranslation(new Vector3f(0,-8,0));
createModel(Asset.marine).setLocalTranslation(new Vector3f(0,-6,0));
createModel(Asset.heer).setLocalTranslation(new Vector3f(0,-4,0));
createModel(Asset.node_normal).setLocalTranslation(new Vector3f(0,-2.5f,0));
createModel(Asset.node_home_blue).setLocalTranslation(new Vector3f(0,-1,0));
createModel(Asset.smallTent).setLocalTranslation(new Vector3f(0,1,0));
createModel(Asset.tank).setLocalTranslation(new Vector3f(0,5,0));
createModel(Asset.jet).setLocalTranslation(new Vector3f(0,12,0));
createModel(Asset.ship).setLocalTranslation(new Vector3f(0,17,0));
createModel(Asset.radar).setLocalTranslation(new Vector3f(0,20,0));
createModel(Asset.world);
//System.out.println(Asset.node_normal.getModelPath());
//System.out.println(Asset.node_normal.getDiffPath());
}
private Spatial createModel(Asset asset){
String modelName = asset.getModelPath();
String texName = asset.getDiffPath();
Spatial model = assetManager.loadModel(modelName);
model.scale(asset.getSize());
model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90));
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", assetManager.loadTexture(texName));
model.setMaterial(mat);
rootNode.attachChild(model);
return model;
} }
@Override @Override

View File

@@ -0,0 +1,64 @@
world 0,0
#Nodes für Map
node_start -1,-5
node -1,-4
node -1,-3
node -1,-2
node_bonus -1,-1
node -2,-1
node -3,-1
node -4,-1
node -5,-1
node -5,0
node_start -5,1
node -4,1
node -3,1
node -2,1
node_bonus -1,1
node -1,2
node -1,3
node -1,4
node -1,5
node 0,5
node_start 1,5
node 1,4
node 1,3
node 1,2
node_bonus 1,1
node 2,1
node 3,1
node 4,1
node 5,1
node 5,0
node_start 5,-1
node 4,-1
node 3,-1
node 2,-1
node_bonus 1,-1
node 1,-2
node 1,-3
node 1,-4
node 1,-5
node 0,-5
#Node Home
node_home_blue 0,-1
node_home_blue 0,-2
node_home_blue 0,-3
node_home_blue 0,-4
node_home_black 0,1
node_home_black 0,2
node_home_black 0,3
node_home_black 0,4
node_home_yellow 1,0
node_home_yellow 2,0
node_home_yellow 3,0
node_home_yellow 4,0
node_home_green -1,0
node_home_green -2,0
node_home_green -3,0
node_home_green -4,0