Add files via upload

This commit is contained in:
JoeMolinelli authored and GitHub committed 2026-08-04 19:50:46 -04:00
1 parent 1cc60fe38c
commit 5177d0fead
44 files changed
+8381

No files matched your search

@@ -0,0 +1,300 @@
package WS3000.weatherstar3000;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Objects;
public class Almanac extends Thread {
Utilities utl = new Utilities();
String today;
String tomorrow;
String todaySunrise;
String todaySunset;
String tomorrowSunrise;
String tomorrowSunset;
String todayLow;
String todayHigh;
String tomorrowHigh;
String tomorrowLow;
String normalPrecip;
String getDay(String icaoCode, String key, int dayNum) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String day = JSONResponse.getJSONArray("dayOfWeek").getString(dayNum);
String[] dayNames = {" SUNDAY ", " MONDAY ", " TUESDAY ", "WEDNESDAY", "THURSDAY ", " FRIDAY ", "SATURDAY "};
return switch (day) {
case "Sunday" -> dayNames[0];
case "Monday" -> dayNames[1];
case "Tuesday" -> dayNames[2];
case "Wednesday" -> dayNames[3];
case "Thursday" -> dayNames[4];
case "Friday" -> dayNames[5];
case "Saturday" -> dayNames[6];
default -> " ";
};
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getSunrise(String icaoCode, String key, int dayNum) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String time = JSONResponse.getJSONArray("sunriseTimeLocal").getString(dayNum);
int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour;
String minutes = time.substring(14, 16);
String part = hour < 12 ? " AM" : " PM";
return utl.rjust(dispHour + ":" + minutes + part, 8, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getSunset(String icaoCode, String key, int dayNum) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String time = JSONResponse.getJSONArray("sunsetTimeLocal").getString(dayNum);
int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour;
String minutes = time.substring(14, 16);
String part = hour < 12 ? " AM" : " PM";
return utl.rjust(dispHour + ":" + minutes + part, 8, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getMonth(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "error";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
} catch (Exception e) {
e.printStackTrace();
return "error";
}
}
String getDayDate(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "error";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
} catch (Exception e) {
e.printStackTrace();
return "error";
}
}
String getTempMax(String icaoCode, String key, int dayNum, String month, String day) {
try {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " ";
}
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int temp = JSONResponse.getJSONArray("temperatureAverageMax").getInt(dayNum);
return utl.rjust(temp + " \\F", 6, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getTempMin(String icaoCode, String key, int dayNum, String month, String day) {
try {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " ";
}
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int temp = JSONResponse.getJSONArray("temperatureAverageMin").getInt(dayNum);
return utl.rjust(temp + " \\F", 6, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getPrecip(String icaoCode, String key, String month, String day) {
try {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " ";
}
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
String[] monthNames = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
JSONObject JSONResponse = new JSONObject(ResponseBody);
float precip = JSONResponse.getJSONArray("precipitationAverage").getFloat(0);
String precipString = utl.rjust(precip + " IN", 8, " ");
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 23, " ");
return utl.ljust(cmonth + precipString, 31, " ") + " ";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
String mainIcao = Main.mainIcao;
String key = Main.key;
String todayMonth = getMonth(mainIcao, key);;
String todayDay = getDayDate(mainIcao, key);;
Main.almanac.today = getDay(mainIcao, key, 0);
Main.almanac.tomorrow = getDay(mainIcao, key, 1);
Main.almanac.todaySunrise = getSunrise(mainIcao, key, 0);
Main.almanac.todaySunset = getSunset(mainIcao, key, 0);
Main.almanac.tomorrowSunrise = getSunrise(mainIcao, key, 1);
Main.almanac.tomorrowSunset = getSunset(mainIcao, key, 1);
Main.almanac.todayHigh = getTempMax(mainIcao, key, 0, todayMonth, todayDay);
Main.almanac.todayLow = getTempMin(mainIcao, key, 0, todayMonth, todayDay);
Main.almanac.tomorrowHigh = getTempMax(mainIcao, key, 1, todayMonth, todayDay);
Main.almanac.tomorrowLow = getTempMin(mainIcao, key, 1, todayMonth, todayDay);
Main.almanac.normalPrecip = getPrecip(mainIcao, key, todayMonth, todayDay);
}
}
@@ -0,0 +1,86 @@
package WS3000.weatherstar3000;
import javazoom.jl.player.Player;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.List;
public class AudioManager extends Thread {
private Player player;
private List<File> playlist;
private volatile boolean finished;
public AudioManager(String folder) {
this.player = null;
this.finished = true;
File musicFolder = new File(folder);
if (!musicFolder.exists() || !musicFolder.isDirectory()) {
System.err.println("\"" + folder + "\" folder not found.");
return;
}
this.playlist = Arrays.asList(musicFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".mp3")));
for (int i = 0; i < this.playlist.size(); i++) {
//System.out.println(getSong(i));
}
}
public List<File> getPlayList() {
return this.playlist;
}
public File getSong(int index) {
return this.playlist.get(index);
}
private void playSong(File file) {
try (FileInputStream fis = new FileInputStream(file)) {
player = new Player(fis);
player.play();
} catch (Exception e) {
System.err.println("Error playing file " + file.getName() + ": " + e.getMessage());
return;
}
}
public void close() {
this.finished = true;
if (player != null) {
player.close();
}
}
public boolean isFinished() {
return finished;
}
public void startPlayList() {
finished = false;
while (!this.finished && playlist != null && !playlist.isEmpty()) {
for (int i = 0; i < this.playlist.size(); i++) {
if (this.finished) {
break;
}
//System.out.println("Playing " + this.playlist.get(i));
playSong(this.playlist.get(i));
}
}
if (player != null) {
player.close();
}
finished = true;
}
public void run() {
startPlayList();
}
}
@@ -0,0 +1,163 @@
package WS3000.weatherstar3000;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Arrays;
import org.json.JSONArray;
import org.json.JSONObject;
import util.Utilities;
public class Bulletin extends Thread {
static Utilities utl = new Utilities();
ArrayList<String> bulletinText = new ArrayList<>();
public ArrayList<String> getBulletin(String key, String lat, String lon) {
ArrayList<String> words = new ArrayList<>();
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
JSONObject responseObject = new JSONObject(Response.body());
for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) {
String headline = responseObject.getJSONArray("alerts").getJSONObject(i).getString("eventDescription");
String detailKey = responseObject.getJSONArray("alerts").getJSONObject(i).getString("detailKey");
if (utl.isScroll(headline)) {
return eachAlert(detailKey, key);
} else {
continue;
}
}
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
}
public ArrayList<String> eachAlert(String detailKey, String key) {
ArrayList<String> words = new ArrayList<>();
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/alerts/detail?alertId=" + detailKey + "&format=json&language=en-US&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
JSONObject ResponseObj = new JSONObject(Response.body());
String headline = ResponseObj.getJSONObject("alertDetail").getString("eventDescription");
String alert = ResponseObj.getJSONObject("alertDetail").getJSONArray("texts").getJSONObject(0).getString("description").toUpperCase();
words.clear();
words.addAll(Arrays.asList(alert.replace("\n\n", " *newline* ").split("\\s+")));
StringBuilder sb = new StringBuilder();
ArrayList<String> finalWords = new ArrayList<>();
finalWords.add(headline);
for (int i = 0; i <= words.size()-1; i++) {
if (words.get(i).equals("*newline*")) {
if (!sb.isEmpty()) {
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
}
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
continue;
}
int wordlength = words.get(i).length();
if (wordlength > 32) {
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
if (!sb.isEmpty()) {sb.append(" ");}
sb.append(words.get(i));
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
} else {
if (wordlength + sb.length() + 1 <= 32) {
if (!sb.isEmpty()) {sb.append(" ");}
sb.append(words.get(i));
} else {
i--;
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
}
}
}
finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
return finalWords;
} catch (Exception e) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
} catch (Exception e) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
}
public void run() {
String key = Main.key;
String mainLat = Main.mainLat;
String mainLon = Main.mainLon;
Main.bulletin.bulletinText.clear();
Main.bulletin.bulletinText = getBulletin(key, mainLat, mainLon);
}
}
@@ -0,0 +1,34 @@
package WS3000.weatherstar3000;
import org.joml.*;
public class Camera {
private Matrix4f projectionMatrix, viewMatrix;
Vector2f position;
public Camera(Vector2f position) {
this.position = position;
this.projectionMatrix = new Matrix4f();
this.viewMatrix = new Matrix4f();
adjustProjection();
}
public void adjustProjection() {
projectionMatrix.identity();
projectionMatrix.ortho(0.0f, 720.0f, 480.0f, 0.0f, 0.0f, 100.0f);
}
public Matrix4f getViewMatrix() {
Vector3f cameraFront = new Vector3f(0.0f, 0.0f, -1.0f);
Vector3f cameraUp = new Vector3f(0.0f, 1.0f, 0.0f);
this.viewMatrix.identity();
viewMatrix = viewMatrix.lookAt(new Vector3f(position.x, position.y, 20.0f),
cameraFront.add(position.x, position.y, 0.0f),
cameraUp);
return this.viewMatrix;
}
public Matrix4f getProjectionMatrix() {
return this.projectionMatrix;
}
}
@@ -0,0 +1,12 @@
package WS3000.weatherstar3000;
public abstract class Component {
public GameObject gameObject = null;
public void start() {
}
public abstract void update(float dt);
}
@@ -0,0 +1,393 @@
package WS3000.weatherstar3000;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
//import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.Month;
public class CurrentConditions extends Thread {
String locName;
String condition;
String temperature;
String feelsLike;
String humidity;
String dewPoint;
String pressure;
String wind;
String gusts;
String visibility;
String ceiling;
String precip;
static Utilities utl = new Utilities();
static String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);}
static String getCondition(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO CURRENT REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return JSONResponse.getString("wxPhraseLong").toUpperCase();
} catch (Exception e) {
e.printStackTrace();
return "NO CURRENT REPORT";
}
} catch (Exception e) {
e.printStackTrace();
return "NO CURRENT REPORT";
}
}
static String getTemperature(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String temp = utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
return "TEMP: " + temp + "\\F";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getFeelsLike(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int feelTemp = JSONResponse.getInt("temperatureFeelsLike");
int temp = JSONResponse.getInt("temperature");
if (temp == feelTemp) {
return " ";
} else {
if (feelTemp > 65) {
return "HEAT INDEX:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
} else {
return "WIND CHILL:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
}
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getHumidity(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String humid = utl.rjust(Integer.toString(JSONResponse.getInt("relativeHumidity")), 3, " ");
return "HUMIDITY: " + humid + "%";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getDewPoint(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String dewpt = utl.rjust(Integer.toString(JSONResponse.getInt("temperatureDewPoint")), 3, " ");
return "DEWPOINT:" + dewpt + "\\F";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getPressure(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
//DecimalFormat df = new DecimalFormat("#.##");
float pres = JSONResponse.getFloat("pressureAltimeter");
String fpres = String.format("%.2f", pres);
int presCode = JSONResponse.getInt("pressureTendencyCode");
String fpresCode = "";
if (presCode == 0) {
fpresCode = "IN.";
} else if (presCode == 1 || presCode == 3) {
fpresCode = "R";
} else if (presCode == 2 || presCode == 4) {
fpresCode = "F";
}
return "BAROMETRIC PRESSURE: " + fpres + " " + fpresCode;
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getWind(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int windDir = JSONResponse.getInt("windDirection");
int windSpeed = JSONResponse.getInt("windSpeed");
if (windSpeed == 0) {
return "WIND: CALM ";
} else {
return "WIND: " + utl.degToThreeLetter(windDir) + utl.rjust(Integer.toString(windSpeed), 3, " ") + " MPH";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getGusts(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String gus;
gus = JSONResponse.isNull("windGust") ? " " : "GUSTS TO " + utl.rjust(Integer.toString(JSONResponse.getInt("windGust")), 3, " ");
return gus;
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
static String getVisiblity(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String visib = utl.rjust(Integer.toString(JSONResponse.getInt("visibility")) + " MI.", 7, " ");
return "VISIB: " + visib;
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getCeiling(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String ceil = JSONResponse.isNull("cloudCeiling") ? "UNLIMITED" : utl.rjust(JSONResponse.getInt("cloudCeiling") + " FT.", 9, " ");
return "CEILING:" + ceil;//three length
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getPrecip(String key, String lat, String lon) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v1/geocode/" + lat + "/" + lon + "/observations/current.json?language=en-US&units=e&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
LocalDate cdate = LocalDate.now();
Month cmonth = cdate.getMonth();
try {
JSONObject obsObject = JSONResponse.getJSONObject("observation");
JSONObject impObj = obsObject.getJSONObject("imperial");
String fprecip = String.format("%.2f", impObj.getFloat("precip_mtd"));
String prec = utl.rjust(fprecip + " IN", 8, " ");
return cmonth.name().toUpperCase() + " PRECIPITATION:" + prec;
} catch (Exception e) {
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
String mainLocName = Main.mainLocName.getText();
String key = Main.key;
String mainIcao = Main.mainIcao;
String mainLat = Main.mainLat;
String mainLon = Main.mainLon;
Main.currentConditions.locName = getLocName(mainLocName);
Main.currentConditions.condition = getCondition(mainIcao, key);
Main.currentConditions.temperature = getTemperature(mainIcao, key);
Main.currentConditions.feelsLike = getFeelsLike(mainIcao, key);
Main.currentConditions.humidity = getHumidity(mainIcao, key);
Main.currentConditions.dewPoint = getDewPoint(mainIcao, key);
Main.currentConditions.pressure = getPressure(mainIcao, key);
Main.currentConditions.wind = getWind(mainIcao, key);
Main.currentConditions.gusts = getGusts(mainIcao, key);
Main.currentConditions.visibility = getVisiblity(mainIcao, key);
Main.currentConditions.ceiling = getCeiling(mainIcao, key);
Main.currentConditions.precip = getPrecip(key, mainLat, mainLon);
}
}
@@ -0,0 +1,50 @@
package WS3000.weatherstar3000;
public class DataRunner extends Thread {
public void run() {
//System.out.println("Data collection");
Main.currentConditions = new CurrentConditions();
Main.hourlyObservations = new HourlyObservations();
Main.regionalConditions = new RegionalConditions();
Main.localForecast = new LocalForecast();
Main.almanac = new Almanac();
Main.regionalForecast = new RegionalForecast();
Main.extendedForecast = new ExtendedForecast();
Main.outlook = new Outlook();
Main.travelForecast = new TravelForecast();
Main.bulletin = new Bulletin();
Main.tides = new Tides();
Main.currentConditions.start();
Main.hourlyObservations.start();
Main.regionalConditions.start();
Main.localForecast.start();
Main.almanac.start();
Main.regionalForecast.start();
Main.extendedForecast.start();
Main.outlook.start();
Main.travelForecast.start();
Main.bulletin.start();
Main.tides.start();
try {
Main.currentConditions.join();
Main.hourlyObservations.join();
Main.regionalConditions.join();
Main.localForecast.join();
Main.almanac.join();
Main.regionalForecast.join();
Main.extendedForecast.join();
Main.outlook.join();
Main.travelForecast.join();
Main.bulletin.join();
Main.tides.join();
LoadingScreen.dataFinish = true;
SlidesRunner.collectingData = false;
//ystem.out.println("data finished, destroying thread");
//wr.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
@@ -0,0 +1,168 @@
package WS3000.weatherstar3000;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import org.json.JSONObject;
import util.Utilities;
public class ExtendedForecast extends Thread {
String dayOne;
String dayTwo;
String dayThree;
ArrayList<String> conditionOne;
ArrayList<String> conditionTwo;
ArrayList<String> conditionThree;
String lowOne;
String lowTwo;
String lowThree;
String highOne;
String highTwo;
String highThree;
Utilities utl = new Utilities();
String getDayName(String icaoCode, String key, int day) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
//JSONObject JSONResponse = new JSONObject(ResponseBody);
//JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
//int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : 0;
return utl.ljust(new JSONObject(ResponseBody).getJSONArray("dayOfWeek").getString(day + 2).toUpperCase(), 10, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
ArrayList<String> getCondition(String icaoCode, String key, int day) {
ArrayList<String> values = new ArrayList<>();
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
values.add(" ");
values.add(" ");
return values;
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 6 : dpData.getJSONArray("dayOrNight").getString(0).equals("N") ? 6 : 4;
int ex = day*2;
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 0));
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 1));
return values;
} catch (Exception e) {
e.printStackTrace();
values.add(" ");
values.add(" ");
return values;
}
} catch (Exception e) {
e.printStackTrace();
values.add(" ");
values.add(" ");
return values;
}
}
String getLow(String icaoCode, String key, int day) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day*2;
return "LO:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump + 1)), 4, " ") + " ";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getHigh(String icaoCode, String key, int day) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day*2;
return "HI:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump)), 4, " ") + " ";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
String key = Main.key;
String mainIcao = Main.mainIcao;
Main.extendedForecast.dayOne = getDayName(mainIcao, key, 0);
Main.extendedForecast.dayTwo = getDayName(mainIcao, key, 1);
Main.extendedForecast.dayThree = getDayName(mainIcao, key, 2);
Main.extendedForecast.conditionOne = getCondition(mainIcao, key, 0);
Main.extendedForecast.conditionTwo = getCondition(mainIcao, key, 1);
Main.extendedForecast.conditionThree = getCondition(mainIcao, key, 2);
Main.extendedForecast.lowOne = getLow(mainIcao, key, 0);
Main.extendedForecast.lowTwo = getLow(mainIcao, key, 1);
Main.extendedForecast.lowThree = getLow(mainIcao, key, 2);
Main.extendedForecast.highOne = getHigh(mainIcao, key, 0);
Main.extendedForecast.highTwo = getHigh(mainIcao, key, 1);
Main.extendedForecast.highThree = getHigh(mainIcao, key, 2);
}
}
@@ -0,0 +1,77 @@
package WS3000.weatherstar3000;
import java.util.ArrayList;
import java.util.List;
public class GameObject {
private String name;
private List<Component> components;
public Transform transform;
private int zIndex;
private boolean visible = true;
public GameObject(String name) {
this.name = name;
this.components = new ArrayList<>();
this.transform = new Transform();
this.zIndex = 0;
this.visible = true;
}
public GameObject(String name, Transform transform, int zIndex) {
this.name = name;
this.zIndex = zIndex;
this.components = new ArrayList<>();
this.transform = transform;
this.visible = true;
}
public <T extends Component> T getComponent(Class<T> componentClass) {
for (Component c : components) {
if (componentClass.isAssignableFrom(c.getClass())) {
try {
return componentClass.cast(c);
} catch (ClassCastException e) {
e.printStackTrace();
assert false : "Error casting component";
}
}
}
return null;
}
public <T extends Component> void removeComponent(Class<T> componentClass) {
for (int i = 0; i < components.size(); i++) {
Component c = components.get(i);
if (componentClass.isAssignableFrom(c.getClass())) {
components.remove(i);
return;
}
}
}
public void addComponent(Component c) {
this.components.add(c);
c.gameObject = this;
}
public void update(float dt) {
for (int i = 0; i < components.size(); i++) {
components.get(i).update(dt);
}
}
public void start() {
for (int i = 0; i <components.size(); i++) {
components.get(i).start();
}
}
public boolean isVisible() {
return this.visible;
}
public int zIndex() {
return this.zIndex;
}
}
@@ -0,0 +1,121 @@
package WS3000.weatherstar3000;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
public class HourlyObservations extends Thread {
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> temperature = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>();
ArrayList<String> wind = new ArrayList<>();
Utilities utl = new Utilities();
String getLocName(String displayName) {
return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
}
String getTemperature(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getCondition(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.getCondition(JSONResponse.getInt("iconCodeExtend"));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getWind(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int windDir = JSONResponse.getInt("windDirection");
int windSpeed = JSONResponse.getInt("windSpeed");
return utl.formatWind(windSpeed, windDir, false);
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
ArrayList<String> nearNames = new ArrayList<>();
nearNames.addAll(Main.nearNames);
ArrayList<String> nearIcaos = new ArrayList<>();;
nearIcaos.addAll(Main.nearIcaos);
String key = Main.key;
Main.hourlyObservations.locName.clear();
Main.hourlyObservations.temperature.clear();
Main.hourlyObservations.condition.clear();
Main.hourlyObservations.wind.clear();
for (int i = 0; i < nearIcaos.size(); i++) {
Main.hourlyObservations.locName.add(getLocName(nearNames.get(i)));
Main.hourlyObservations.temperature.add(getTemperature(nearIcaos.get(i), key));
Main.hourlyObservations.condition.add(getCondition(nearIcaos.get(i), key));
Main.hourlyObservations.wind.add(getWind(nearIcaos.get(i), key));
}
}
}
@@ -0,0 +1,39 @@
package WS3000.weatherstar3000;
import static org.lwjgl.glfw.GLFW.*;
public class KeyListener {
private static KeyListener instance;
private boolean keyPressed[] = new boolean[350];
private KeyListener() {
}
public static KeyListener get() {
if (KeyListener.instance == null) {
KeyListener.instance = new KeyListener();
}
return KeyListener.instance;
}
public static void keyCallback(long window, int key, int scancode, int action, int mods) {
if (key >= 0 && key <= 350) {
if (action == GLFW_PRESS) {
get().keyPressed[key] = true;
} else if (action == GLFW_RELEASE) {
get().keyPressed[key] = false;
}
}
return;
}
public static boolean isKeyPressed(int keyCode) {
if (keyCode >= 0 && keyCode <= 350) {
return get().keyPressed[keyCode];
} else {
return false;
}
}
}
@@ -0,0 +1,115 @@
package WS3000.weatherstar3000;
import java.util.ArrayList;
import org.joml.Vector2f;
import org.joml.Vector4f;
import components.SpriteRenderer;
import components.Spritesheet;
import util.AssetPool;
import util.Utilities;
public class LoadingScreen extends Scene {
Vector4f color1 = new Vector4f(82.0f/255.0f, 80.0f/255.0f, 80.0f/255.0f, 1.0f); //gray
Vector4f color2 = new Vector4f(11.0f/255.0f, 104.0f/255.0f, 6.0f/255.0f, 1.0f); //green
Vector4f color3 = new Vector4f(61.0f/255.0f, 0.0f/255.0f, 109.0f/255.0f, 1.0f); //purple
Vector4f color4 = new Vector4f(104.0f/255.0f, 0.0f/255.0f, 8.0f/255.0f, 1.0f); //red
Vector4f color5 = new Vector4f(4.0f/255.0f, 92.0f/255.0f, 82.0f/255.0f, 1.0f); //cyan
Vector4f color6 = new Vector4f(46.0f/255.0f, 2.0f/255.0f, 120.0f/255.0f, 1.0f); //blue BG
Vector4f color7 = new Vector4f(124.0f/255.0f, 104.0f/255.0f, 6.0f/255.0f, 1.0f); //gold
Vector4f color8 = new Vector4f(3.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); //black
Vector4f color9 = new Vector4f(106.0f/255.0f, 80.0f/255.0f, 57.0f/255.0f, 1.0f); //brown
Vector4f color10 = new Vector4f(116.0f/255.0f, 133.0f/255.0f, 22.0f/255.0f, 1.0f); //yellow
Vector4f color11 = new Vector4f(60.0f/255.0f, 0.0f/255.0f, 109.0f/255.0f, 1.0f); //purple (again?)
Vector4f color12 = new Vector4f(132.0f/255.0f, 81.0f/255.0f, 74.0f/255.0f, 1.0f); //peach
Vector4f color13 = new Vector4f(83.0f/255.0f, 77.0f/255.0f, 1.0f/255.0f, 1.0f); //hazel
Vector4f color14 = new Vector4f(9.0f/255.0f, 121.0f/255.0f, 172.0f/255.0f, 1.0f); //light blue
Vector4f color15 = new Vector4f(160.0f/255.0f, 78.0f/255.0f, 14.0f/255.0f, 1.0f); //orange
Vector4f color16 = new Vector4f(188.0f/255.0f, 190.0f/255.0f, 189.0f/255.0f, 1.0f); //white
Vector4f greenScreen = new Vector4f(0.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f, 1.0f);
Utilities utl = new Utilities();
Spritesheet sprites;
boolean dataInit = false;
static boolean dataFinish = false;
public LoadingScreen() {
}
@Override
public void init() {
System.out.println("start loading screen");
loadResources();
this.camera = new Camera(new Vector2f(0, 0));
sprites = AssetPool.getSpritesheet("/resources/images/charMap.png");
ArrayList<String> lines = new ArrayList<>();
GameObject[] lsPool = new GameObject[256];
for (int i = 0; i < lsPool.length; i++) {
lsPool[i] = new GameObject("ccPool" + i, new Transform(new Vector2f()), 0);
lsPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
}
lines.add("LOADING DATA...");
lines.add(" ");
lines.add("MADE WITH JAVA, LWJGL, OPENGL,");
lines.add("AND JLAYER BY JAVAZOOM");
lines.add("BROUGHT TO YOU BY");
lines.add("JOE MOLINELLI");
lines.add("AND MIST WEATHER MEDIA");
int textX = 81;
int textY = 44;
int poolIdx = 0;
for (int row = 0; row < lines.size(); row++) {
int lineHeight = 40;
String line = lines.get(row);
for (int i = 0; i < line.length(); i ++) {
if (poolIdx >= lsPool.length) break;
char c = line.charAt(i);
GameObject go = lsPool[poolIdx++];
go.transform.position.set(textX, textY);
go.transform.scale.set(18, 32);
SpriteRenderer sr = go.getComponent(SpriteRenderer.class);
sr.setSprite(sprites.getSprite(utl.getMainChar(c)));
this.addGameObjectToScene(go);
if (i % 2 != 0) textX++;
textX += 17;
}
textX = 81;
textY += lineHeight;
}
}
private void loadResources() {
AssetPool.getShader("/resources/shaders/default.glsl");
AssetPool.addSpritesheet("/resources/images/charMap.png", new Spritesheet(AssetPool.getTexture("/resources/images/charMap.png"),32, 32, 128, 0));
}
@Override
public void update(float dt) {
if (!dataInit) {
dataInit = true;
DataRunner data = new DataRunner();
data.start();
}
for (GameObject go : this.gameObjects) {
go.update(dt);
}
this.renderer.render();
if (dataFinish) {
Window.finishInit();
}
}
}
@@ -0,0 +1,130 @@
package WS3000.weatherstar3000;
import org.json.JSONArray;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Arrays;
public class LocalForecast extends Thread {
ArrayList<String> bulletin = new ArrayList<>();
ArrayList<String> forecastOne = new ArrayList<>();
ArrayList<String> forecastTwo = new ArrayList<>();
ArrayList<String> forecastThree = new ArrayList<>();
Utilities utl = new Utilities();
ArrayList<String> getForecast(String icaoCode, String key, int forecastId) {
ArrayList<String> words = new ArrayList<>();
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.add("NO");
words.add("REPORT");
return words;
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : dpData.getJSONArray("dayOrNight").getString(0).equals("N") ? 1 : 0;
String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", JSONResponse.getJSONArray("dayOfWeek").getString(1)).toUpperCase() +
"..." +
dpData.getJSONArray("narrative").getString(forecastId + bump).toUpperCase();
String[] splitwords = fullText.split("\\s+");
words.addAll(Arrays.asList(splitwords));
return words;
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("NO");
words.add("REPORT");
return words;
}
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("NO");
words.add("REPORT");
return words;
}
}
ArrayList<String> getBulletin(String key, String lat, String lon) {
ArrayList<String> words = new ArrayList<>();
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.add("NOBULLETIN");
return words;
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONArray alertData = JSONResponse.getJSONArray("alerts");
StringBuilder fullText = new StringBuilder();
fullText.setLength(0);
for (int i = 0; i < alertData.length(); i++) {
if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) {
if (!fullText.isEmpty()) {fullText.append(" *NEWLINE* ");}
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase());
}
}
words.clear();
if (!fullText.isEmpty()) {
String[] splitwords = fullText.toString().split("\\s+");
words.addAll(Arrays.asList(splitwords));
} else {
words.add("NOBULLETIN");
}
return words;
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("NOBULLETIN");
return words;
}
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("NOBULLETIN");
return words;
}
}
public void run() {
String mainIcao = Main.mainIcao;
String key = Main.key;
String mainLat = Main.mainLat;
String mainLon = Main.mainLon;
Main.localForecast.bulletin = getBulletin(key, mainLat, mainLon);
Main.localForecast.forecastOne = getForecast(mainIcao, key, 0);
Main.localForecast.forecastTwo = getForecast(mainIcao, key, 1);
Main.localForecast.forecastThree = getForecast(mainIcao, key, 2);
}
}
@@ -0,0 +1,954 @@
package WS3000.weatherstar3000;
import org.json.JSONException;
import org.json.JSONObject;
import util.Utilities;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.net.URISyntaxException;
public class Main {
static String selectedFlavor;
static ArrayList<String> ldlList = new ArrayList<>(Arrays.asList("cityname", "condition", "temperature", "humidity", "pressure", "wind", "visibility", "precip"));
static boolean settingsErrorThrown = false;
static ArrayList<String> settingsErrorReasons = new ArrayList<>();
static String popupErrors = "";
static boolean loopSlides = false;
static boolean greenScreen = false;
static String key;
static String mainIcao;
static String mainLon;
static String mainLat;
static int simWidth;
static int simHeight;
static boolean fullscreen = false;
// static String mainName;
static DataRunner dr;
static CurrentConditions currentConditions;
static HourlyObservations hourlyObservations;
static RegionalConditions regionalConditions;
static LocalForecast localForecast;
static Almanac almanac;
static RegionalForecast regionalForecast;
static ExtendedForecast extendedForecast;
static Outlook outlook;
static TravelForecast travelForecast;
static Bulletin bulletin;
static Tides tides;
static JFrame settingsWindow;
static ArrayList<String> nearNames = new ArrayList<>();
static ArrayList<String> nearIcaos = new ArrayList<>();
static ArrayList<String> regConNames = new ArrayList<>();
static ArrayList<String> regConIcaos = new ArrayList<>();
static ArrayList<String> regForNames = new ArrayList<>();
static ArrayList<String> regForIcaos = new ArrayList<>();
static ArrayList<String> tideIDs = new ArrayList<>();
static ArrayList<String> tideNames = new ArrayList<>();
static String adCrawl;
static boolean tidesEnabled = false;
static String jarFolder = "";
static JTextField mainLocName;
public static void main(String[] args) throws InterruptedException {
/*
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (UnsupportedLookAndFeelException e) {
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
*/
//things to add:
//airport conditions
//air quality
//timezone switch?
System.out.println("WeatherSTAR 3000 Simulator Version 1.5.3");
String userDir = System.getProperty("user.dir");
if (userDir != null && !userDir.isEmpty()) {
jarFolder = userDir;
} else {
jarFolder = new File(".").getAbsolutePath();
}
// read
File loadDataFile = new File(jarFolder + File.separator + "loadData.txt");
ArrayList<String> loadDataLines = new ArrayList<>();
settingsWindow = new JFrame("WeatherSTAR 3000 Settings");
settingsWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
settingsWindow.setSize(460, 350);
settingsWindow.setLocationRelativeTo(null);
settingsWindow.setResizable(false);
ImageIcon sfIcon = new ImageIcon(Main.class.getResource("/resources/images/icon.png"));
settingsWindow.setIconImage(sfIcon.getImage());
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 10));
JPanel aPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
aPanel.setBorder(BorderFactory.createTitledBorder("IBM Api Key From api.weather.com"));
JTextField apiKeyText = new JTextField(25);
aPanel.add(apiKeyText);
aPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, aPanel.getPreferredSize().height));
contentPanel.add(aPanel);
JPanel mlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
mlPanel.setBorder(BorderFactory.createTitledBorder("Main Location"));
mlPanel.add(new JLabel("ICAO Code"));
JTextField mainLocIcaoCode = new JTextField(5);
mlPanel.add(mainLocIcaoCode);
mlPanel.add(new JLabel("Location Name"));
mainLocName = new JTextField(15);
mlPanel.add(mainLocName);
mlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, mlPanel.getPreferredSize().height));
contentPanel.add(mlPanel);
JPanel nbPanel = new JPanel(new GridLayout(0, 1, 0, 0));
nbPanel.setBorder(BorderFactory.createTitledBorder("Nearby Locations"));
JPanel nb1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb1Panel.add(new JLabel("ICAO Code"));
JTextField nearLocOneIcaoCode = new JTextField(5);
nb1Panel.add(nearLocOneIcaoCode);
nb1Panel.add(new JLabel("Location Name"));
JTextField nearLocOneName = new JTextField(15);
nb1Panel.add(nearLocOneName);
nbPanel.add(nb1Panel);
JPanel nb2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb2Panel.add(new JLabel("ICAO Code"));
JTextField nearLocTwoIcaoCode = new JTextField(5);
nb2Panel.add(nearLocTwoIcaoCode);
nb2Panel.add(new JLabel("Location Name"));
JTextField nearLocTwoName = new JTextField(15);
nb2Panel.add(nearLocTwoName);
nbPanel.add(nb2Panel);
JPanel nb3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb3Panel.add(new JLabel("ICAO Code"));
JTextField nearLocThreeIcaoCode = new JTextField(5);
nb3Panel.add(nearLocThreeIcaoCode);
nb3Panel.add(new JLabel("Location Name"));
JTextField nearLocThreeName = new JTextField(15);
nb3Panel.add(nearLocThreeName);
nbPanel.add(nb3Panel);
JPanel nb4Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb4Panel.add(new JLabel("ICAO Code"));
JTextField nearLocFourIcaoCode = new JTextField(5);
nb4Panel.add(nearLocFourIcaoCode);
nb4Panel.add(new JLabel("Location Name"));
JTextField nearLocFourName = new JTextField(15);
nb4Panel.add(nearLocFourName);
nbPanel.add(nb4Panel);
JPanel nb5Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb5Panel.add(new JLabel("ICAO Code"));
JTextField nearLocFiveIcaoCode = new JTextField(5);
nb5Panel.add(nearLocFiveIcaoCode);
nb5Panel.add(new JLabel("Location Name"));
JTextField nearLocFiveName = new JTextField(15);
nb5Panel.add(nearLocFiveName);
nbPanel.add(nb5Panel);
JPanel nb6Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb6Panel.add(new JLabel("ICAO Code"));
JTextField nearLocSixIcaoCode = new JTextField(5);
nb6Panel.add(nearLocSixIcaoCode);
nb6Panel.add(new JLabel("Location Name"));
JTextField nearLocSixName = new JTextField(15);
nb6Panel.add(nearLocSixName);
nbPanel.add(nb6Panel);
JPanel nb7Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
nb7Panel.add(new JLabel("ICAO Code"));
JTextField nearLocSevenIcaoCode = new JTextField(5);
nb7Panel.add(nearLocSevenIcaoCode);
nb7Panel.add(new JLabel("Location Name"));
JTextField nearLocSevenName = new JTextField(15);
nb7Panel.add(nearLocSevenName);
nbPanel.add(nb7Panel);
nbPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, nbPanel.getPreferredSize().height));
contentPanel.add(nbPanel);
JPanel rcPanel = new JPanel(new GridLayout(0, 1, 0, 0));
rcPanel.setBorder(BorderFactory.createTitledBorder("Regional Conditions Locations"));
JPanel rc1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc1Panel.add(new JLabel("ICAO Code"));
JTextField regConOneIcaoCode = new JTextField(5);
rc1Panel.add(regConOneIcaoCode);
rc1Panel.add(new JLabel("Location Name"));
JTextField regConOneName = new JTextField(15);
rc1Panel.add(regConOneName);
rcPanel.add(rc1Panel);
JPanel rc2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc2Panel.add(new JLabel("ICAO Code"));
JTextField regConTwoIcaoCode = new JTextField(5);
rc2Panel.add(regConTwoIcaoCode);
rc2Panel.add(new JLabel("Location Name"));
JTextField regConTwoName = new JTextField(15);
rc2Panel.add(regConTwoName);
rcPanel.add(rc2Panel);
JPanel rc3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc3Panel.add(new JLabel("ICAO Code"));
JTextField regConThreeIcaoCode = new JTextField(5);
rc3Panel.add(regConThreeIcaoCode);
rc3Panel.add(new JLabel("Location Name"));
JTextField regConThreeName = new JTextField(15);
rc3Panel.add(regConThreeName);
rcPanel.add(rc3Panel);
JPanel rc4Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc4Panel.add(new JLabel("ICAO Code"));
JTextField regConFourIcaoCode = new JTextField(5);
rc4Panel.add(regConFourIcaoCode);
rc4Panel.add(new JLabel("Location Name"));
JTextField regConFourName = new JTextField(15);
rc4Panel.add(regConFourName);
rcPanel.add(rc4Panel);
JPanel rc5Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc5Panel.add(new JLabel("ICAO Code"));
JTextField regConFiveIcaoCode = new JTextField(5);
rc5Panel.add(regConFiveIcaoCode);
rc5Panel.add(new JLabel("Location Name"));
JTextField regConFiveName = new JTextField(15);
rc5Panel.add(regConFiveName);
rcPanel.add(rc5Panel);
JPanel rc6Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc6Panel.add(new JLabel("ICAO Code"));
JTextField regConSixIcaoCode = new JTextField(5);
rc6Panel.add(regConSixIcaoCode);
rc6Panel.add(new JLabel("Location Name"));
JTextField regConSixName = new JTextField(15);
rc6Panel.add(regConSixName);
rcPanel.add(rc6Panel);
JPanel rc7Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rc7Panel.add(new JLabel("ICAO Code"));
JTextField regConSevenIcaoCode = new JTextField(5);
rc7Panel.add(regConSevenIcaoCode);
rc7Panel.add(new JLabel("Location Name"));
JTextField regConSevenName = new JTextField(15);
rc7Panel.add(regConSevenName);
rcPanel.add(rc7Panel);
rcPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, rcPanel.getPreferredSize().height));
contentPanel.add(rcPanel);
JPanel rfPanel = new JPanel(new GridLayout(0, 1, 0, 0));
rfPanel.setBorder(BorderFactory.createTitledBorder("Regional Forecast Locations"));
JPanel rf1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf1Panel.add(new JLabel("ICAO Code"));
JTextField regForOneIcaoCode = new JTextField(5);
rf1Panel.add(regForOneIcaoCode);
rf1Panel.add(new JLabel("Location Name"));
JTextField regForOneName = new JTextField(15);
rf1Panel.add(regForOneName);
rfPanel.add(rf1Panel);
JPanel rf2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf2Panel.add(new JLabel("ICAO Code"));
JTextField regForTwoIcaoCode = new JTextField(5);
rf2Panel.add(regForTwoIcaoCode);
rf2Panel.add(new JLabel("Location Name"));
JTextField regForTwoName = new JTextField(15);
rf2Panel.add(regForTwoName);
rfPanel.add(rf2Panel);
JPanel rf3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf3Panel.add(new JLabel("ICAO Code"));
JTextField regForThreeIcaoCode = new JTextField(5);
rf3Panel.add(regForThreeIcaoCode);
rf3Panel.add(new JLabel("Location Name"));
JTextField regForThreeName = new JTextField(15);
rf3Panel.add(regForThreeName);
rfPanel.add(rf3Panel);
JPanel rf4Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf4Panel.add(new JLabel("ICAO Code"));
JTextField regForFourIcaoCode = new JTextField(5);
rf4Panel.add(regForFourIcaoCode);
rf4Panel.add(new JLabel("Location Name"));
JTextField regForFourName = new JTextField(15);
rf4Panel.add(regForFourName);
rfPanel.add(rf4Panel);
JPanel rf5Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf5Panel.add(new JLabel("ICAO Code"));
JTextField regForFiveIcaoCode = new JTextField(5);
rf5Panel.add(regForFiveIcaoCode);
rf5Panel.add(new JLabel("Location Name"));
JTextField regForFiveName = new JTextField(15);
rf5Panel.add(regForFiveName);
rfPanel.add(rf5Panel);
JPanel rf6Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf6Panel.add(new JLabel("ICAO Code"));
JTextField regForSixIcaoCode = new JTextField(5);
rf6Panel.add(regForSixIcaoCode);
rf6Panel.add(new JLabel("Location Name"));
JTextField regForSixName = new JTextField(15);
rf6Panel.add(regForSixName);
rfPanel.add(rf6Panel);
JPanel rf7Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
rf7Panel.add(new JLabel("ICAO Code"));
JTextField regForSevenIcaoCode = new JTextField(5);
rf7Panel.add(regForSevenIcaoCode);
rf7Panel.add(new JLabel("Location Name"));
JTextField regForSevenName = new JTextField(15);
rf7Panel.add(regForSevenName);
rfPanel.add(rf7Panel);
rfPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, rfPanel.getPreferredSize().height));
contentPanel.add(rfPanel);
//tides
JPanel tPanel = new JPanel(new GridLayout(0, 1, 0, 0));
tPanel.setBorder(BorderFactory.createTitledBorder("Tides Locations"));
JPanel t1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
t1Panel.add(new JLabel("Station ID"));
JTextField tideOneID = new JTextField(5);
t1Panel.add(tideOneID);
t1Panel.add(new JLabel("Location Name"));
JTextField tideOneName = new JTextField(15);
t1Panel.add(tideOneName);
tPanel.add(t1Panel);
JPanel t2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
t2Panel.add(new JLabel("Station ID"));
JTextField tideTwoID = new JTextField(5);
t2Panel.add(tideTwoID);
t2Panel.add(new JLabel("Location Name"));
JTextField tideTwoName = new JTextField(15);
t2Panel.add(tideTwoName);
tPanel.add(t2Panel);
tPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, tPanel.getPreferredSize().height));
contentPanel.add(tPanel);
//ad crawl
JPanel cPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
cPanel.setBorder(BorderFactory.createTitledBorder("Ad Crawl"));
JTextField adCrawlInput = new JTextField(35);
cPanel.add(adCrawlInput);
cPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, cPanel.getPreferredSize().height));
contentPanel.add(cPanel);
JPanel rPanel = new JPanel(new GridLayout(0, 1, 0, 0));
rPanel.setBorder(BorderFactory.createTitledBorder("Run Simulation"));
JPanel r1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
r1Panel.add(new JLabel("Width"));
JTextField widthField = new JTextField(3);
r1Panel.add(widthField);
widthField.setText("720");
r1Panel.add(new JLabel("Height"));
JTextField heightField = new JTextField(3);
heightField.setText("480");
r1Panel.add(heightField);
r1Panel.add(new JLabel("Flavor"));
String[] flavorOptions = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"};
JComboBox flavorDropdown = new JComboBox(flavorOptions);
flavorDropdown.setSelectedIndex(0);
r1Panel.add(flavorDropdown);
rPanel.add(r1Panel);
JPanel r2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
r2Panel.add(new JLabel("LDL Options"));
String[] ldlOptions = {"Observations", "Ad Crawl", "Both"};
JComboBox ldlDropdown = new JComboBox(ldlOptions);
ldlDropdown.setSelectedIndex(0);
r2Panel.add(ldlDropdown);
rPanel.add(r2Panel);
JPanel r3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JCheckBox tidesCheck = new JCheckBox("Tides");
r3Panel.add(tidesCheck);
JCheckBox loopCheck = new JCheckBox("Loop");
r3Panel.add(loopCheck);
JCheckBox gsCheck = new JCheckBox("Green Screen");
r3Panel.add(gsCheck);
JCheckBox fsCheck = new JCheckBox("Fullscreen");
r3Panel.add(fsCheck);
rPanel.add(r3Panel);
JPanel r4Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton doneButton = new JButton("Run");
r4Panel.add(doneButton);
JButton saveButton = new JButton("Save Config");
r4Panel.add(saveButton);
JButton loadButton = new JButton("Load Config");
r4Panel.add(loadButton);
r4Panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, rPanel.getPreferredSize().height));
rPanel.add(r4Panel);
contentPanel.add(rPanel);
//final
JScrollPane scrollPanel = new JScrollPane(contentPanel);
scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPanel.getVerticalScrollBar().setUnitIncrement(16);
mainPanel.add(scrollPanel, BorderLayout.CENTER);
settingsWindow.setContentPane(mainPanel);
try (Scanner myReader = new Scanner(loadDataFile)) {
while (myReader.hasNextLine()) {
loadDataLines.add(myReader.nextLine());
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(mainPanel, "Unable to read previous data.");
}
apiKeyText.setText(loadDataLines.get(0));
mainLocIcaoCode.setText(loadDataLines.get(1));
mainLocName.setText(loadDataLines.get(2));
nearLocOneIcaoCode.setText(loadDataLines.get(3));
nearLocOneName.setText(loadDataLines.get(4));
nearLocTwoIcaoCode.setText(loadDataLines.get(5));
nearLocTwoName.setText(loadDataLines.get(6));
nearLocThreeIcaoCode.setText(loadDataLines.get(7));
nearLocThreeName.setText(loadDataLines.get(8));
nearLocFourIcaoCode.setText(loadDataLines.get(9));
nearLocFourName.setText(loadDataLines.get(10));
nearLocFiveIcaoCode.setText(loadDataLines.get(11));
nearLocFiveName.setText(loadDataLines.get(12));
nearLocSixIcaoCode.setText(loadDataLines.get(13));
nearLocSixName.setText(loadDataLines.get(14));
nearLocSevenIcaoCode.setText(loadDataLines.get(15));
nearLocSevenName.setText(loadDataLines.get(16));
regConOneIcaoCode.setText(loadDataLines.get(17));
regConOneName.setText(loadDataLines.get(18));
regConTwoIcaoCode.setText(loadDataLines.get(19));
regConTwoName.setText(loadDataLines.get(20));
regConThreeIcaoCode.setText(loadDataLines.get(21));
regConThreeName.setText(loadDataLines.get(22));
regConFourIcaoCode.setText(loadDataLines.get(23));
regConFourName.setText(loadDataLines.get(24));
regConFiveIcaoCode.setText(loadDataLines.get(25));
regConFiveName.setText(loadDataLines.get(26));
regConSixIcaoCode.setText(loadDataLines.get(27));
regConSixName.setText(loadDataLines.get(28));
regConSevenIcaoCode.setText(loadDataLines.get(29));
regConSevenName.setText(loadDataLines.get(30));
regForOneIcaoCode.setText(loadDataLines.get(31));
regForOneName.setText(loadDataLines.get(32));
regForTwoIcaoCode.setText(loadDataLines.get(33));
regForTwoName.setText(loadDataLines.get(34));
regForThreeIcaoCode.setText(loadDataLines.get(35));
regForThreeName.setText(loadDataLines.get(36));
regForFourIcaoCode.setText(loadDataLines.get(37));
regForFourName.setText(loadDataLines.get(38));
regForFiveIcaoCode.setText(loadDataLines.get(39));
regForFiveName.setText(loadDataLines.get(40));
regForSixIcaoCode.setText(loadDataLines.get(41));
regForSixName.setText(loadDataLines.get(42));
regForSevenIcaoCode.setText(loadDataLines.get(43));
regForSevenName.setText(loadDataLines.get(44));
tideOneID.setText(loadDataLines.get(45));
tideOneName.setText(loadDataLines.get(46));
tideTwoID.setText(loadDataLines.get(47));
tideTwoName.setText(loadDataLines.get(48));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Select a directory to save you config");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFolder = chooser.getSelectedFile();
String fileName = JOptionPane.showInputDialog(null, "Name the config file?");
// 3. Create the JSON content
String jsonContent = String.format(
"{\"starSettings\": {"
+ "\"api_key\": \"" + apiKeyText.getText() + "\","
+ "\"mainLocation\": {"
+ "\"icaoCode\": \"" + mainLocIcaoCode.getText() + "\","
+ "\"locName\": \"" + mainLocName.getText() + "\""
+ "},"
+ "\"nearbyLocations\": ["
+ "{\"icaoCode\": \"" + nearLocOneIcaoCode.getText() + "\", \"locName\": \"" + nearLocOneName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocTwoIcaoCode.getText() + "\", \"locName\": \"" + nearLocTwoName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocThreeIcaoCode.getText() + "\", \"locName\": \"" + nearLocThreeName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocFourIcaoCode.getText() + "\", \"locName\": \"" + nearLocFourName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocFiveIcaoCode.getText() + "\", \"locName\": \"" + nearLocFiveName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocSixIcaoCode.getText() + "\", \"locName\": \"" + nearLocSixName.getText() + "\"},"
+ "{\"icaoCode\": \"" + nearLocSevenIcaoCode.getText() + "\", \"locName\": \"" + nearLocSevenName.getText() + "\"}"
+ "],"
+ "\"regionalForecastLocations\": ["
+ "{\"icaoCode\": \"" + regForOneIcaoCode.getText() + "\", \"locName\": \"" + regForOneName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForTwoIcaoCode.getText() + "\", \"locName\": \"" + regForTwoName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForThreeIcaoCode.getText() + "\", \"locName\": \"" + regForThreeName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForFourIcaoCode.getText() + "\", \"locName\": \"" + regForFourName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForFiveIcaoCode.getText() + "\", \"locName\": \"" + regForFiveName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForSixIcaoCode.getText() + "\", \"locName\": \"" + regForSixName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regForSevenIcaoCode.getText() + "\", \"locName\": \"" + regForSevenName.getText() + "\"}"
+ "],"
+ "\"regionalConditionsLocations\": ["
+ "{\"icaoCode\": \"" + regConOneIcaoCode.getText() + "\", \"locName\": \"" + regConOneName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConTwoIcaoCode.getText() + "\", \"locName\": \"" + regConTwoName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConThreeIcaoCode.getText() + "\", \"locName\": \"" + regConThreeName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConFourIcaoCode.getText() + "\", \"locName\": \"" + regConFourName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConFiveIcaoCode.getText() + "\", \"locName\": \"" + regConFiveName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConSixIcaoCode.getText() + "\", \"locName\": \"" + regConSixName.getText() + "\"},"
+ "{\"icaoCode\": \"" + regConSevenIcaoCode.getText() + "\", \"locName\": \"" + regConSevenName.getText() + "\"}"
+ "],"
+ "\"tideLocations\": ["
+ "{\"id\":\"" + tideOneID.getText() + "\", \"locName\":\"" + tideOneName.getText() + "\"},"
+ "{\"id\":\"" + tideTwoID.getText() + "\", \"locName\":\"" + tideTwoName.getText() + "\"}"
+ "]"
+ "}}"
);
// 4. Save to the folder
if (fileName != null && !fileName.trim().isEmpty()) {
if (!fileName.endsWith(".json")) fileName += ".json";
} else {
fileName = "myConfig.json";
}
File fileToSave = new File(selectedFolder, fileName);
try (FileWriter writer = new FileWriter(fileToSave)) {
writer.write(jsonContent);
JOptionPane.showMessageDialog(null, "Saved to: " + fileToSave.getAbsolutePath());
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(mainPanel, "Error saving config file.");
}
}
}
});
loadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser openFile = new JFileChooser();
int returnval = openFile.showOpenDialog(null);
File loadedFile = openFile.getSelectedFile();
Path filePath;
String absFilePath;
String loadedExtension;
if (returnval == JFileChooser.APPROVE_OPTION) {
filePath = Paths.get(loadedFile.getAbsolutePath());
absFilePath = loadedFile.getAbsolutePath();
try {
loadedExtension = Files.probeContentType(filePath);
} catch (IOException ex) {
loadedExtension = "error";
}
if (!loadedExtension.equals("application/json")) {
JOptionPane.showMessageDialog(mainPanel, "Please choose a json file.");
} else {
StringBuilder jsonText = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(absFilePath));
String line;
while ((line = br.readLine()) != null) {
jsonText.append(line).append("\n");
}
br.close();
JSONObject settingsObj = new JSONObject(jsonText.toString()).getJSONObject("starSettings");
// api key
apiKeyText.setText(settingsObj.getString("api_key"));
// main location
mainLocIcaoCode.setText(settingsObj.getJSONObject("mainLocation").getString("icaoCode"));
mainLocName.setText(settingsObj.getJSONObject("mainLocation").getString("locName"));
// nearby cities
nearLocOneIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(0).getString("icaoCode"));
nearLocOneName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(0).getString("locName"));
nearLocTwoIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(1).getString("icaoCode"));
nearLocTwoName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(1).getString("locName"));
nearLocThreeIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(2).getString("icaoCode"));
nearLocThreeName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(2).getString("locName"));
nearLocFourIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(3).getString("icaoCode"));
nearLocFourName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(3).getString("locName"));
nearLocFiveIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(4).getString("icaoCode"));
nearLocFiveName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(4).getString("locName"));
nearLocSixIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(5).getString("icaoCode"));
nearLocSixName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(5).getString("locName"));
nearLocSevenIcaoCode.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(6).getString("icaoCode"));
nearLocSevenName.setText(
settingsObj.getJSONArray("nearbyLocations").getJSONObject(6).getString("locName"));
// regional conditions
regConOneIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(0).getString("icaoCode"));
regConOneName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(0).getString("locName"));
regConTwoIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(1).getString("icaoCode"));
regConTwoName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(1).getString("locName"));
regConThreeIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(2).getString("icaoCode"));
regConThreeName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(2).getString("locName"));
regConFourIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(3).getString("icaoCode"));
regConFourName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(3).getString("locName"));
regConFiveIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(4).getString("icaoCode"));
regConFiveName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(4).getString("locName"));
regConSixIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(5).getString("icaoCode"));
regConSixName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(5).getString("locName"));
regConSevenIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(6).getString("icaoCode"));
regConSevenName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
.getJSONObject(6).getString("locName"));
// regional forecast
regForOneIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(0).getString("icaoCode"));
regForOneName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(0).getString("locName"));
regForTwoIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(1).getString("icaoCode"));
regForTwoName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(1).getString("locName"));
regForThreeIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(2).getString("icaoCode"));
regForThreeName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(2).getString("locName"));
regForFourIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(3).getString("icaoCode"));
regForFourName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(3).getString("locName"));
regForFiveIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(4).getString("icaoCode"));
regForFiveName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(4).getString("locName"));
regForSixIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(5).getString("icaoCode"));
regForSixName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(5).getString("locName"));
regForSevenIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(6).getString("icaoCode"));
regForSevenName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(6).getString("locName"));
// tides
tideOneID.setText(settingsObj.getJSONArray("tideLocations").getJSONObject(0).getString("id"));
tideOneName.setText(settingsObj.getJSONArray("tideLocations").getJSONObject(0).getString("locName"));
tideTwoID.setText(settingsObj.getJSONArray("tideLocations").getJSONObject(1).getString("id"));
tideTwoName.setText(settingsObj.getJSONArray("tideLocations").getJSONObject(1).getString("locName"));
// after all of that, change the base config json that loads on start
String dataFilePath = jarFolder + File.separator + "loadData.txt";
String content = apiKeyText.getText() + "\n" + mainLocIcaoCode.getText() + "\n"
+ mainLocName.getText() + "\n" + nearLocOneIcaoCode.getText() + "\n"
+ nearLocOneName.getText() + "\n" + nearLocTwoIcaoCode.getText() + "\n"
+ nearLocTwoName.getText() + "\n" + nearLocThreeIcaoCode.getText() + "\n"
+ nearLocThreeName.getText() + "\n" + nearLocFourIcaoCode.getText() + "\n"
+ nearLocFourName.getText() + "\n" + nearLocFiveIcaoCode.getText() + "\n"
+ nearLocFiveName.getText() + "\n" + nearLocSixIcaoCode.getText() + "\n"
+ nearLocSixName.getText() + "\n" + nearLocSevenIcaoCode.getText() + "\n"
+ nearLocSevenName.getText() + "\n" + regConOneIcaoCode.getText() + "\n"
+ regConOneName.getText() + "\n" + regConTwoIcaoCode.getText() + "\n"
+ regConTwoName.getText() + "\n" + regConThreeIcaoCode.getText() + "\n"
+ regConThreeName.getText() + "\n" + regConFourIcaoCode.getText() + "\n"
+ regConFourName.getText() + "\n" + regConFiveIcaoCode.getText() + "\n"
+ regConFiveName.getText() + "\n" + regConSixIcaoCode.getText() + "\n"
+ regConSixName.getText() + "\n" + regConSevenIcaoCode.getText() + "\n"
+ regConSevenName.getText() + "\n" + regForOneIcaoCode.getText() + "\n"
+ regForOneName.getText() + "\n" + regForTwoIcaoCode.getText() + "\n"
+ regForTwoName.getText() + "\n" + regForThreeIcaoCode.getText() + "\n"
+ regForThreeName.getText() + "\n" + regForFourIcaoCode.getText() + "\n"
+ regForFourName.getText() + "\n" + regForFiveIcaoCode.getText() + "\n"
+ regForFiveName.getText() + "\n" + regForSixIcaoCode.getText() + "\n"
+ regForSixName.getText() + "\n" + regForSevenIcaoCode.getText() + "\n"
+ regForSevenName.getText() + "\n" + tideOneID.getText() + "\n"
+ tideOneName.getText() + "\n" + tideTwoID.getText() + "\n"
+ tideTwoName.getText() + "\n";
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dataFilePath))) {
writer.write(content);
writer.close();
} catch (IOException y) {
y.printStackTrace();
JOptionPane.showMessageDialog(mainPanel,
"Error saving loaded config data to program. Config will not load on next startup.");
}
} catch (JSONException ex) {
JOptionPane.showMessageDialog(mainPanel,
"Unable to read loaded configuration file, please choose a valid file.");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
});
doneButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loopSlides = loopCheck.isSelected();
greenScreen = gsCheck.isSelected();
fullscreen = fsCheck.isSelected();
key = apiKeyText.getText();
mainIcao = mainLocIcaoCode.getText();
tidesEnabled = tidesCheck.isSelected();
nearIcaos.add(nearLocOneIcaoCode.getText());
nearIcaos.add(nearLocTwoIcaoCode.getText());
nearIcaos.add(nearLocThreeIcaoCode.getText());
nearIcaos.add(nearLocFourIcaoCode.getText());
nearIcaos.add(nearLocFiveIcaoCode.getText());
nearIcaos.add(nearLocSixIcaoCode.getText());
nearIcaos.add(nearLocSevenIcaoCode.getText());
nearNames.add(nearLocOneName.getText());
nearNames.add(nearLocTwoName.getText());
nearNames.add(nearLocThreeName.getText());
nearNames.add(nearLocFourName.getText());
nearNames.add(nearLocFiveName.getText());
nearNames.add(nearLocSixName.getText());
nearNames.add(nearLocSevenName.getText());
regConIcaos.add(regConOneIcaoCode.getText());
regConIcaos.add(regConTwoIcaoCode.getText());
regConIcaos.add(regConThreeIcaoCode.getText());
regConIcaos.add(regConFourIcaoCode.getText());
regConIcaos.add(regConFiveIcaoCode.getText());
regConIcaos.add(regConSixIcaoCode.getText());
regConIcaos.add(regConSevenIcaoCode.getText());
regConNames.add(regConOneName.getText());
regConNames.add(regConTwoName.getText());
regConNames.add(regConThreeName.getText());
regConNames.add(regConFourName.getText());
regConNames.add(regConFiveName.getText());
regConNames.add(regConSixName.getText());
regConNames.add(regConSevenName.getText());
regForIcaos.add(regForOneIcaoCode.getText());
regForIcaos.add(regForTwoIcaoCode.getText());
regForIcaos.add(regForThreeIcaoCode.getText());
regForIcaos.add(regForFourIcaoCode.getText());
regForIcaos.add(regForFiveIcaoCode.getText());
regForIcaos.add(regForSixIcaoCode.getText());
regForIcaos.add(regForSevenIcaoCode.getText());
regForNames.add(regForOneName.getText());
regForNames.add(regForTwoName.getText());
regForNames.add(regForThreeName.getText());
regForNames.add(regForFourName.getText());
regForNames.add(regForFiveName.getText());
regForNames.add(regForSixName.getText());
regForNames.add(regForSevenName.getText());
tideIDs.add(tideOneID.getText());
tideIDs.add(tideTwoID.getText());
tideNames.add(tideOneName.getText());
tideNames.add(tideTwoName.getText());
adCrawl = adCrawlInput.getText();
WindowRunner wr = new WindowRunner();
String ldltype = (String) ldlDropdown.getSelectedItem();
switch (ldltype) {
case "Observations":
SlidesRunner.ccType = "obs";
break;
case "Ad Crawl":
SlidesRunner.ccType = "crawl";
break;
case "Both":
SlidesRunner.ccType = "both";
break;
default:
System.out.println("Invalid LDL Option");
break;
}
selectedFlavor = (String) flavorDropdown.getSelectedItem();
simWidth = Integer.parseInt(widthField.getText());
simHeight = Integer.parseInt(heightField.getText());
mainLat = icaoToLat(mainIcao, key);
mainLon = icaoToLon(mainIcao, key);
wr.start();
settingsErrorThrown = false;
settingsErrorReasons.clear();
popupErrors = "";
}
});
settingsWindow.setVisible(true);
}
static String checkIcaoCode(String code, String key) {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
+ "&language=en-US&format=json&apiKey=" + key))
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
.header("Accept", "application/json").build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
if (Response.statusCode() == 401) {
return "API Key error";
} else {
return "Invalid ICAO Code";
}
}
return "noerror";
} catch (Exception e) {
e.printStackTrace();
return "Server Error";
}
}
static String icaoToLat(String code, String key) {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
+ "&language=en-US&format=json&apiKey=" + key))
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
.header("Accept", "application/json").build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject locationObject = JSONResponse.getJSONObject("location");
return Float.toString(locationObject.getFloat("latitude"));
} catch (Exception e) {
e.printStackTrace();
return "Server Error";
}
}
static String icaoToLon(String code, String key) {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
+ "&language=en-US&format=json&apiKey=" + key))
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
.header("Accept", "application/json").build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject locationObject = JSONResponse.getJSONObject("location");
return Float.toString(locationObject.getFloat("longitude"));
} catch (Exception e) {
e.printStackTrace();
return "Server Error";
}
}
}
@@ -0,0 +1,98 @@
package WS3000.weatherstar3000;
import static org.lwjgl.glfw.GLFW.*;
public class MouseListener {
private static MouseListener instance;
private double scrollX, scrollY;
private double xPos, yPos, lastX, lastY;
private boolean mouseButtonPressed[] = new boolean[3];
private boolean isDragging;
private MouseListener() {
this.scrollX = 0.0;
this.scrollY = 0.0;
this.xPos = 0.0;
this.yPos = 9.0;
this.lastX = 0.0;
this.lastY = 0.0;
}
public static MouseListener get() {
if (MouseListener.instance == null) {
MouseListener.instance = new MouseListener();
}
return MouseListener.instance;
}
public static void mousePosCallback(long window, double xpos, double ypos) {
get().lastX = get().xPos;
get().lastY = get().yPos;
get().xPos = xpos;
get().yPos = ypos;
get().isDragging = get().mouseButtonPressed[0] || get().mouseButtonPressed[1] || get().mouseButtonPressed[2];
}
public static void mouseButtonCallback(long window, int button, int action, int mods) {
if (action == GLFW_PRESS) {
if (button < get().mouseButtonPressed.length) {
get().mouseButtonPressed[button] = true;
}
} else if (action == GLFW_RELEASE) {
if (button < get().mouseButtonPressed.length) {
get().mouseButtonPressed[button] = false;
get().isDragging = false;
}
}
}
public static void mouseScrollCallback(long window, double xOffset, double yOffset) {
get().scrollX = xOffset;
get().scrollY = yOffset;
}
public static void endFrame() {
get().scrollX = 0;
get().scrollY = 0;
get().lastX = get().xPos;
get().lastY = get().yPos;
}
public static float getX() {
return (float)get().xPos;
}
public static float getY() {
return (float)get().yPos;
}
public static float getDx() {
return (float)(get().lastX - get().xPos);
}
public static float getDy() {
return (float)(get().lastY - get().yPos);
}
public static float getScrollX() {
return (float)get().scrollX;
}
public static float getScrollY() {
return (float)get().scrollY;
}
public static boolean isDragging() {
return get().isDragging;
}
public static boolean mouseButtonDown(int button) {
if (button < get().mouseButtonPressed.length) {
return get().mouseButtonPressed[button];
} else {
return false;
}
}
}
@@ -0,0 +1,47 @@
package WS3000.weatherstar3000;
//import java.net.URI;
//import java.net.http.HttpClient;
//import java.net.http.HttpRequest;
//import java.net.http.HttpResponse;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import util.Utilities;
//import org.json.JSONObject;
public class Outlook extends Thread {
static Utilities utl = new Utilities();
String month;
ArrayList<String> outlook = new ArrayList<>();
String getMonth() {
try {
LocalDate cdate = LocalDate.now();
Month cmonth = cdate.getMonth();
return cmonth.name().toUpperCase();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
ArrayList<String> getOutlook() {
ArrayList<String> outlook = new ArrayList<>();
try {
outlook.add("NO");
outlook.add("REPORT");
return outlook;
} catch (Exception e) {
e.printStackTrace();
outlook.add("NO");
outlook.add("REPORT");
return outlook;
}
}
public void run() {
Main.outlook.month = getMonth();
Main.outlook.outlook = getOutlook();
}
}
@@ -0,0 +1,89 @@
package WS3000.weatherstar3000;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
public class RegionalConditions extends Thread {
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> temperature = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>();
Utilities utl = new Utilities();
String getLocName(String displayName){
return utl.ljust(displayName, 19, " ").toUpperCase().substring(0, 19);
}
String getCondition(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.getCondition(JSONResponse.getInt("iconCodeExtend"));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getTemperature(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
ArrayList<String> regConNames = new ArrayList<>();
regConNames.addAll(Main.regConNames);
ArrayList<String> regConIcaos = new ArrayList<>();
regConIcaos.addAll(Main.regConIcaos);
String key = Main.key;
Main.regionalConditions.locName.clear();
Main.regionalConditions.temperature.clear();
Main.regionalConditions.condition.clear();
for (int i = 0; i < regConIcaos.size(); i++) {
Main.regionalConditions.locName.add(getLocName(regConNames.get(i)));
Main.regionalConditions.temperature.add(getTemperature(regConIcaos.get(i), key));
Main.regionalConditions.condition.add(getCondition(regConIcaos.get(i), key));
}
}
}
@@ -0,0 +1,127 @@
package WS3000.weatherstar3000;
import org.json.JSONObject;
import util.Utilities;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.LocalTime;
import java.util.ArrayList;
public class RegionalForecast extends Thread {
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>();
ArrayList<String> low = new ArrayList<>();
ArrayList<String> high = new ArrayList<>();
String first;
Utilities utl = new Utilities();
String getLocName(String displayName){
return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
}
String getCondition(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getLow(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getHigh(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
ArrayList<String> regForNames = new ArrayList<>();
regForNames.addAll(Main.regForNames);
ArrayList<String> regForIcaos = new ArrayList<>();
regForIcaos.addAll(Main.regForIcaos);
String key = Main.key;
Main.regionalForecast.locName.clear();
Main.regionalForecast.condition.clear();
Main.regionalForecast.low.clear();
Main.regionalForecast.high.clear();
for (int i = 0; i < regForIcaos.size(); i++) {
Main.regionalForecast.locName.add(getLocName(regForNames.get(i)));
Main.regionalForecast.condition.add(getCondition(regForIcaos.get(i), key));
Main.regionalForecast.low.add(getLow(regForIcaos.get(i), key));
Main.regionalForecast.high.add(getHigh(regForIcaos.get(i), key));
}
int hr = LocalTime.now().getHour();
Main.regionalForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
}
}
@@ -0,0 +1,45 @@
package WS3000.weatherstar3000;
import java.util.ArrayList;
import java.util.List;
import renderer.Renderer;
public abstract class Scene {
protected Renderer renderer = new Renderer();
protected Camera camera;
private boolean isRunning = false;
protected List<GameObject> gameObjects = new ArrayList<>();
public Scene() {
}
public void init() {
}
public void start() {
for (GameObject go : gameObjects) {
go.start();
this.renderer.add(go);
}
isRunning = true;
}
public void addGameObjectToScene(GameObject go) {
if (!isRunning) {
gameObjects.add(go);
} else {
gameObjects.add(go);
go.start();
this.renderer.add(go);
}
}
public abstract void update(float dt);
public Camera camera() {
return this.camera;
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,121 @@
package WS3000.weatherstar3000;
import util.Utilities;
import org.json.JSONArray;
import org.json.JSONObject;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class Tides extends Thread {
Utilities utl = new Utilities();
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> highTide = new ArrayList<>();
ArrayList<String> lowTide = new ArrayList<>();
String sunrise;
String sunset;
DateTimeFormatter tideDateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
DateTimeFormatter tideTimeFormatter = DateTimeFormatter.ofPattern("h:mma E", Locale.ENGLISH);
String getLocName(String displayName) {
return utl.cjust(displayName, 32, " ").toUpperCase().substring(0, 32);
}
String getTides(String station, String tide) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date=" + LocalDate.now().format(tideDateFormatter) + "&end_date=" + LocalDate.now().plusDays(1).format(tideDateFormatter) + "&station=" + station + "&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=json"))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONArray predictions = new JSONObject(ResponseBody).getJSONArray("predictions");
StringBuilder sb = new StringBuilder();
int j = 0;
for (int i = 0; i < predictions.length(); i++) {
if (predictions.getJSONObject(i).getString("type").equals(tide)) {
sb.append(utl.rjust(LocalDateTime.parse(predictions.getJSONObject(i).getString("t"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")).format(tideTimeFormatter).toUpperCase(Locale.ENGLISH), 11, " "));
if (j < 1) sb.append(" ");
j++;
if (j == 2) break;
}
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getSunData(String icaoCode, String key, String type) {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String time = JSONResponse.getJSONArray(type).getString(0);
int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour;
String minutes = time.substring(14, 16);
String part = hour < 12 ? "AM" : "PM";
return utl.rjust(dispHour + ":" + minutes + part, 7, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
ArrayList<String> tideIDs = new ArrayList<>();
tideIDs.addAll(Main.tideIDs);
ArrayList<String> tideNames = new ArrayList<>();
tideNames.addAll(Main.tideNames);
String key = Main.key;
Main.tides.highTide.clear();
Main.tides.lowTide.clear();
for (int i = 0; i < tideIDs.size(); i++) {
Main.tides.locName.add(getLocName(Main.tideNames.get(i)));
Main.tides.highTide.add(getTides(Main.tideIDs.get(i), "H"));
Main.tides.lowTide.add(getTides(Main.tideIDs.get(i), "L"));
}
Main.tides.sunrise = getSunData(Main.mainIcao, key, "sunriseTimeLocal");
Main.tides.sunset = getSunData(Main.mainIcao, key, "sunsetTimeLocal");
}
}
@@ -0,0 +1,44 @@
package WS3000.weatherstar3000;
import org.joml.Vector2f;
public class Transform {
public Vector2f position;
public Vector2f scale;
public Transform() {
init(new Vector2f(), new Vector2f());
}
public Transform(Vector2f position) {
init(position, new Vector2f());
}
public Transform(Vector2f position, Vector2f scale) {
init(position, scale);
}
public void init(Vector2f position, Vector2f scale) {
this.position = position;
this.scale = scale;
}
public Transform copy() {
return new Transform(new Vector2f(this.position), new Vector2f(this.scale));
}
public void copy(Transform to) {
to.position.set(this.position);
to.scale.set(this.scale);
}
@Override
public boolean equals(Object o) {
if (o == null) return false;
if (!(o instanceof Transform)) return false;
Transform t = (Transform)o;
return t.position.equals(this.position) && t.scale.equals(this.scale);
}
}
@@ -0,0 +1,127 @@
package WS3000.weatherstar3000;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import org.json.JSONObject;
import util.Utilities;
public class TravelForecast extends Thread {
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>();
ArrayList<String> low = new ArrayList<>();
ArrayList<String> high = new ArrayList<>();
Utilities utl = new Utilities();
String first;
ArrayList<String> tForNames = new ArrayList<>(Arrays.asList("ATLANTA", "BISMARCK", "BOISE", "BOSTON", "BUFFALO", "CHICAGO", "CINCINNATI", "DALLAS", "DENVER", "DETROIT", "KANSAS CITY", "LOS ANGELES", "MINNEAPOLIS", "NASHVILLE", "NEW ORLEANS", "NEW YORK CITY", "PHOENIX", "PORTLAND", "RALEIGH", "RAPID CITY", "SACRAMENTO", "SALT LAKE CITY", "TAMPA", "WASHINGTON, DC"));
ArrayList<String> tForIcaos = new ArrayList<>(Arrays.asList("KATL", "KBIS", "KBOI", "KBOS", "KBUF", "KORD", "KCVG", "KDAL", "KDEN", "KDTW", "KMCI", "KLAX", "KMSP", "KDNA", "KMSY", "KLGA", "KPHX", "KPDX", "KRDU", "KRAP", "KSMF", "KSLC", "KTPA", "KDCA"));
String getLocName(String displayName){
return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
}
String getCondition(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getLow(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getHigh(String icaoCode, String key) {
try {
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
String key = Main.key;
Main.travelForecast.locName.clear();
Main.travelForecast.condition.clear();
Main.travelForecast.high.clear();
Main.travelForecast.low.clear();
for (int i = 0; i < tForIcaos.size(); i++) {
Main.travelForecast.locName.add(getLocName(tForNames.get(i)));
Main.travelForecast.condition.add(getCondition(tForIcaos.get(i), key));
Main.travelForecast.low.add(getLow(tForIcaos.get(i), key));
Main.travelForecast.high.add(getHigh(tForIcaos.get(i), key));
}
int hr = LocalTime.now().getHour();
Main.travelForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
}
}
@@ -0,0 +1,210 @@
package WS3000.weatherstar3000;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.opengl.GL30.glGenFramebuffers;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
import static org.lwjgl.opengl.GL30.*;
import renderer.FrameBuffer;
public class Window {
static int secFrameCount;
static int fourSecFrameCount;
static int slidesSecFrameCount;
static int crawlSecFrameCount;
static int bTimerSecFrameCount;
static int bSlideSecFrameCount;
int width, height;
String title;
private FrameBuffer framebuffer;
private static long glfwWindow;
public float r, g, b, a;
private static boolean fullscreen;
private static Window window;
private static Scene currentScene;
private Window(int width, int height, boolean fullscreen) {
this.width = width;
this.height = height;
this.title = "WeatherSTAR 3000";
this.fullscreen = fullscreen;
r = 0.0f;
g = 0.0f;
b = 0.0f;
a = 1.0f;
}
public static Window get() {
if (Window.window == null) {
Window.window = new Window(Main.simWidth, Main.simHeight, Main.fullscreen);
}
return Window.window;
}
public static long getGLFWWindow() {
return glfwWindow;
}
public static Scene getScene() {
return get().currentScene;
}
public void runWindow() {
System.out.println("LWJGL" + Version.getVersion());
init();
loop();
glfwFreeCallbacks(glfwWindow);
glfwDestroyWindow(glfwWindow);
glfwTerminate();
glfwSetErrorCallback(null).free();
}
public void init() {
GLFWErrorCallback.createPrint(System.err).set();
//glfwInitHint(GLFW.GLFW_PLATFORM, GLFW.GLFW_PLATFORM_WAYLAND);
if (!glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
PointerBuffer monitors = glfwGetMonitors();
if (!monitors.equals(NULL)) {
for (int i = 0; i < monitors.limit(); i++) {
long monitorHandle = monitors.get(i);
// Get the human-readable name of the monitor
String monitorName = glfwGetMonitorName(monitorHandle);
System.out.println("Monitor " + i + ": " + monitorName);
}
} else {
System.err.println("No monitors found!");
}
if (this.fullscreen) {
glfwWindow = glfwCreateWindow(vidMode.width(), vidMode.height(), "WeatherSTAR 3000", GLFW.glfwGetPrimaryMonitor(), NULL);
} else {
glfwWindow = glfwCreateWindow(this.width, this.height, "WeatherSTAR 3000", NULL, NULL);
}
if (glfwWindow == NULL) {
throw new IllegalStateException("Failed to create GLFW window");
}
glfwSetFramebufferSizeCallback(glfwWindow, (windowHandle, newWidth, newHeight) -> {
this.width = newWidth;
this.height = newHeight;
glViewport(0, 0, newWidth, newHeight);
});
glfwSetKeyCallback(glfwWindow, KeyListener::keyCallback);
glfwMakeContextCurrent(glfwWindow);
glfwSwapInterval(1);
GL.createCapabilities();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glfwShowWindow(glfwWindow);
//this.framebuffer = new FrameBuffer(this.width, this.height);
currentScene = new LoadingScreen();
currentScene.init();
currentScene.start();
}
public void loop() {
float beginTime = (float)glfwGetTime();
float endTime;
float dt = 0.0f;
secFrameCount = 0;
System.out.println("start window");
while(!glfwWindowShouldClose(glfwWindow)) {
glfwPollEvents();
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
if (KeyListener.isKeyPressed(GLFW_KEY_ESCAPE)) {
System.exit(0);
}
if (dt >= 0) {
currentScene.update(dt);
}
glfwSwapBuffers(glfwWindow);
endTime = (float)glfwGetTime();
if (SlidesRunner.slidesStarted) {
secFrameCount++;
fourSecFrameCount++;
slidesSecFrameCount++;
if (!SlidesRunner.bulletinActive) {
bTimerSecFrameCount++;
}
if (SlidesRunner.adCrawlActive) {
crawlSecFrameCount++;
}
}
dt = endTime - beginTime;
//System.out.println(1.0f/dt + " fps");
beginTime = endTime;
}
if (SlidesRunner.audioManager != null) {
SlidesRunner.audioManager.close();
}
System.exit(0);
}
static void finishInit() {
currentScene = new SlidesRunner();
currentScene.init();
currentScene.start();
}
}
@@ -0,0 +1,9 @@
package WS3000.weatherstar3000;
public class WindowRunner extends Thread {
public void run() {
Main.settingsWindow.setVisible(false);
Window window = Window.get();
window.runWindow();
}
}