-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WPR-15 - Add mission details, general refactor
- Loading branch information
Showing
21 changed files
with
337 additions
and
74 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/org/faulty/wpreplace/models/MissionDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.faulty.wpreplace.models; | ||
|
||
import lombok.Data; | ||
import org.luaj.vm2.LuaTable; | ||
import org.luaj.vm2.LuaValue; | ||
|
||
@Data | ||
public class MissionDetails { | ||
private final Date date; | ||
private final String theatre; | ||
private final MissionWeather weather; | ||
|
||
public static MissionDetails fromLuaMission(LuaValue missionLua) { | ||
return new MissionDetails(getDate(missionLua.get("date").checktable()), | ||
missionLua.get("theatre").tojstring(), | ||
MissionWeather.fromLua(missionLua.get("weather").checktable())); | ||
} | ||
|
||
private static Date getDate(LuaTable luaDate) { | ||
return new Date( | ||
luaDate.get("Year").toint(), | ||
luaDate.get("Month").toint(), | ||
luaDate.get("Day").toint() | ||
); | ||
} | ||
|
||
@Data | ||
public static class Date { | ||
private final int year; | ||
private final int month; | ||
private final int day; | ||
|
||
@Override | ||
public String toString() { | ||
return day + "/" + month + "/" + year; | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/org/faulty/wpreplace/models/MissionWeather.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.faulty.wpreplace.models; | ||
|
||
import lombok.Data; | ||
import org.luaj.vm2.LuaTable; | ||
import org.luaj.vm2.LuaValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Data | ||
public class MissionWeather { | ||
private final int atmosphereType; | ||
private final List<Wind> winds; | ||
private final boolean enableFog; | ||
private final int fogThickness; | ||
private final int fogVisibility; | ||
private final int seasonTemperature; | ||
private final String name; | ||
private final List<Item> clouds; | ||
|
||
public static MissionWeather fromLua(LuaTable weatherLua) { | ||
return new MissionWeather( | ||
weatherLua.get("atmosphere_type").toint(), | ||
getWinds(weatherLua.get("wind").checktable()), | ||
weatherLua.get("enable_fog").toboolean(), | ||
weatherLua.get("fog").get("thickness").toint(), | ||
weatherLua.get("fog").get("visibility").toint(), | ||
weatherLua.get("season").get("temperature").toint(), | ||
weatherLua.get("name").tojstring(), | ||
getClouds(weatherLua.get("clouds").checktable()) | ||
); | ||
} | ||
|
||
private static List<Item> getClouds(LuaTable cloudsLua) { | ||
List<Item> pylonsPayload = new ArrayList<>(); | ||
for (LuaValue key : cloudsLua.keys()) { | ||
pylonsPayload.add(new Item(key.tojstring(), cloudsLua.get(key).tojstring())); | ||
} | ||
return pylonsPayload; | ||
} | ||
|
||
private static List<Wind> getWinds(LuaTable windLua) { | ||
List<Wind> winds = new ArrayList<>(); | ||
for (LuaValue key : windLua.keys()) { | ||
winds.add(new Wind( | ||
key.tojstring(), | ||
windLua.get(key).get("speed").toint(), | ||
windLua.get(key).get("dir").toint() | ||
)); | ||
} | ||
return winds; | ||
} | ||
|
||
@Data | ||
public static class Wind { | ||
private final String location; | ||
private final int speed; | ||
private final int dir; | ||
} | ||
|
||
@Data | ||
public static final class Item { | ||
private final String key; | ||
private final String value; | ||
|
||
public Item(String key, Object value) { | ||
this.key = key; | ||
this.value = String.valueOf(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/org/faulty/wpreplace/ui/GeneralMissionDetailsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.faulty.wpreplace.ui; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.control.cell.PropertyValueFactory; | ||
import javafx.scene.text.Text; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.faulty.wpreplace.models.MissionDetails; | ||
import org.faulty.wpreplace.models.MissionWeather; | ||
import org.faulty.wpreplace.services.MissionService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Log4j2 | ||
@Component | ||
public class GeneralMissionDetailsController { | ||
@Autowired | ||
private MissionService missionService; | ||
|
||
@FXML | ||
public Text dateText; | ||
@FXML | ||
public Text theatreText; | ||
|
||
@FXML | ||
private TableView<MissionWeather.Item> dataTable; | ||
@FXML | ||
public TableView<MissionWeather.Wind> windTable; | ||
@FXML | ||
public TableView<MissionWeather.Item> cloudsTable; | ||
|
||
public void initialize() { | ||
MissionDetails missionDetails = MissionDetails.fromLuaMission(missionService.getMission()); | ||
dateText.setText(missionDetails.getDate().toString()); | ||
theatreText.setText(missionDetails.getTheatre()); | ||
initGeneralDate(missionDetails); | ||
initWindTable(missionDetails); | ||
initCloudsTable(missionDetails); | ||
|
||
|
||
} | ||
|
||
private void initCloudsTable(MissionDetails missionDetails) { | ||
TableColumn<MissionWeather.Item, String> keyColumn = new TableColumn<>("Key"); | ||
keyColumn.setCellValueFactory(new PropertyValueFactory<>("key")); | ||
|
||
TableColumn<MissionWeather.Item, String> valColumn = new TableColumn<>("Value"); | ||
valColumn.setCellValueFactory(new PropertyValueFactory<>("value")); | ||
|
||
cloudsTable.getColumns().addAll(keyColumn, valColumn); | ||
cloudsTable.getItems().addAll(missionDetails.getWeather().getClouds()); | ||
} | ||
|
||
private void initWindTable(MissionDetails missionDetails) { | ||
TableColumn<MissionWeather.Wind, String> altColumn = new TableColumn<>("Altitude"); | ||
altColumn.setCellValueFactory(new PropertyValueFactory<>("location")); | ||
|
||
TableColumn<MissionWeather.Wind, String> speedColumn = new TableColumn<>("Speed"); | ||
speedColumn.setCellValueFactory(new PropertyValueFactory<>("speed")); | ||
|
||
TableColumn<MissionWeather.Wind, String> dirColumn = new TableColumn<>("Direction"); | ||
dirColumn.setCellValueFactory(new PropertyValueFactory<>("dir")); | ||
|
||
windTable.getColumns().addAll(altColumn, speedColumn, dirColumn); | ||
windTable.getItems().addAll(missionDetails.getWeather().getWinds()); | ||
} | ||
|
||
private void initGeneralDate(MissionDetails missionDetails) { | ||
TableColumn<MissionWeather.Item, String> typeColumn = new TableColumn<>("Key"); | ||
typeColumn.setCellValueFactory(new PropertyValueFactory<>("key")); | ||
|
||
TableColumn<MissionWeather.Item, String> valueColumn = new TableColumn<>("Value"); | ||
valueColumn.setCellValueFactory(new PropertyValueFactory<>("value")); | ||
|
||
dataTable.getColumns().addAll(typeColumn, valueColumn); | ||
MissionWeather weather = missionDetails.getWeather(); | ||
dataTable.setItems(FXCollections.observableArrayList(List.of( | ||
new MissionWeather.Item("Name", weather.getName()), | ||
new MissionWeather.Item("Atmosphere Type", weather.getAtmosphereType()), | ||
new MissionWeather.Item("Enable Fog", weather.isEnableFog()), | ||
new MissionWeather.Item("Fog Thickness", weather.getFogThickness()), | ||
new MissionWeather.Item("Fog Visibility", weather.getFogVisibility()), | ||
new MissionWeather.Item("Season Temperature", weather.getSeasonTemperature()) | ||
))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.