diff --git a/src/main/java/WS3000/weatherstar3000/Almanac.java b/src/main/java/WS3000/weatherstar3000/Almanac.java new file mode 100644 index 0000000..f55be96 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Almanac.java @@ -0,0 +1,257 @@ +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) { + 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 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 " "; + } + } + String getSunrise(String icaoCode, String key, int dayNum) { + 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 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 " "; + } + } + String getSunset(String icaoCode, String key, int dayNum) { + 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 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 " "; + } + } + String getMonth(String icaoCode, String key) { + 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 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"; + } + } + String getDayDate(String icaoCode, String key) { + 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 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"; + } + } + String getTempMax(String icaoCode, String key, int dayNum, String month, String day) { + 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 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 " "; + } + } + String getTempMin(String icaoCode, String key, int dayNum, String month, String day) { + 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 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 " "; + } + } + String getPrecip(String icaoCode, String key, String month, String day) { + 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 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 " "; + } + } + public void run() { + String mainIcao = Main.mainIcao; + String key = Main.key; + String todayMonth = Main.todayMonth; + String todayDay = Main.todayDay; + 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); + } +} \ No newline at end of file diff --git a/src/main/java/WS3000/weatherstar3000/AudioManager.java b/src/main/java/WS3000/weatherstar3000/AudioManager.java new file mode 100644 index 0000000..15222d7 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/AudioManager.java @@ -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 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 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(); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Bulletin.java b/src/main/java/WS3000/weatherstar3000/Bulletin.java new file mode 100644 index 0000000..0b834be --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Bulletin.java @@ -0,0 +1,152 @@ +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 bulletinText = new ArrayList<>(); + //String color; + //boolean severe; + //boolean crawl; + + public ArrayList getBulletin(String key, String lat, String lon) { + ArrayList words = new ArrayList<>(); + 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 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; + } + } + + public ArrayList eachAlert(String detailKey, String key) { + ArrayList words = new ArrayList<>(); + + 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 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 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; + } + } + + public void run() { + String key = Main.key; + String mainLat = Main.mainLat; + String mainLon = Main.mainLon; + Main.bulletin.bulletinText = getBulletin(key, mainLat, mainLon); + //System.out.println(Main.bulletin.bulletinText); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Camera.java b/src/main/java/WS3000/weatherstar3000/Camera.java new file mode 100644 index 0000000..9709101 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Camera.java @@ -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; + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Component.java b/src/main/java/WS3000/weatherstar3000/Component.java new file mode 100644 index 0000000..4ee40e5 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Component.java @@ -0,0 +1,12 @@ +package WS3000.weatherstar3000; + +public abstract class Component { + + public GameObject gameObject = null; + + public void start() { + + } + + public abstract void update(float dt); +} \ No newline at end of file diff --git a/src/main/java/WS3000/weatherstar3000/CurrentConditions.java b/src/main/java/WS3000/weatherstar3000/CurrentConditions.java new file mode 100644 index 0000000..fd1912d --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/CurrentConditions.java @@ -0,0 +1,338 @@ +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) { + 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 Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); + if (Response.statusCode() != 200) { + return "NO REPORT"; + } + String ResponseBody = Response.body(); + JSONObject JSONResponse = new JSONObject(ResponseBody); + + return JSONResponse.getString("wxPhraseLong").toUpperCase(); + } catch (Exception e) { + e.printStackTrace(); + return "NO REPORT"; + } + } + static String getTemperature(String icaoCode, String key) { + 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 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 " "; + } + } + static String getFeelsLike(String icaoCode, String key) { + 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 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 " "; + } + } + static String getHumidity(String icaoCode, String key) { + 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 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 " "; + } + } + static String getDewPoint(String icaoCode, String key) { + 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 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 " "; + } + } + static String getPressure(String icaoCode, String key) { + 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 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 " "; + } + } + static String getWind(String icaoCode, String key) { + 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 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 " "; + } + } + static String getGusts(String icaoCode, String key) { + 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 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 " "; + } + } + static String getVisiblity(String icaoCode, String key) { + 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 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 " "; + } + } + String getCeiling(String icaoCode, String key) { + 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 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 " "; + } + } + String getPrecip(String key, String lat, String lon) { + 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 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 " "; + } + } + 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); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/DataRunner.java b/src/main/java/WS3000/weatherstar3000/DataRunner.java new file mode 100644 index 0000000..f04bfbf --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/DataRunner.java @@ -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(); + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/ExtendedForecast.java b/src/main/java/WS3000/weatherstar3000/ExtendedForecast.java new file mode 100644 index 0000000..e4c7687 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/ExtendedForecast.java @@ -0,0 +1,146 @@ +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 conditionOne; + ArrayList conditionTwo; + ArrayList 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) { + 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 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 " "; + } + } + ArrayList getCondition(String icaoCode, String key, int day) { + ArrayList values = new ArrayList<>(); + 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 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) ? 5 : 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; + } + } + String getLow(String icaoCode, String key, int day) { + 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 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 " "; + } + } + String getHigh(String icaoCode, String key, int day) { + 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 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 " "; + } + } + 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); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/GameObject.java b/src/main/java/WS3000/weatherstar3000/GameObject.java new file mode 100644 index 0000000..40f37b2 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/GameObject.java @@ -0,0 +1,77 @@ +package WS3000.weatherstar3000; + +import java.util.ArrayList; +import java.util.List; + +public class GameObject { + private String name; + private List 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 getComponent(Class 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 void removeComponent(Class 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 locName = new ArrayList<>(); + ArrayList temperature = new ArrayList<>(); + ArrayList condition = new ArrayList<>(); + ArrayList wind = new ArrayList<>(); + Utilities utl = new Utilities(); + + String getLocName(String displayName) { + return utl.ljust(displayName, 14, " ").substring(0, 14); + } + String getTemperature(String icaoCode, String key) { + 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 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 " "; + } + } + String getCondition(String icaoCode, String key) { + 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 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"; + } + } + String getWind(String icaoCode, String key) { + 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 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 " "; + } + } + public void run() { + ArrayList nearNames = new ArrayList<>(); + nearNames.addAll(Main.nearNames); + ArrayList nearIcaos = new ArrayList<>();; + nearIcaos.addAll(Main.nearIcaos); + String key = Main.key; + 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)); + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/KeyListener.java b/src/main/java/WS3000/weatherstar3000/KeyListener.java new file mode 100644 index 0000000..ad5841e --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/KeyListener.java @@ -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; + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/LoadingScreen.java b/src/main/java/WS3000/weatherstar3000/LoadingScreen.java new file mode 100644 index 0000000..c222525 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/LoadingScreen.java @@ -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 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(); + } + } + +} diff --git a/src/main/java/WS3000/weatherstar3000/LocalForecast.java b/src/main/java/WS3000/weatherstar3000/LocalForecast.java new file mode 100644 index 0000000..5d1ce17 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/LocalForecast.java @@ -0,0 +1,113 @@ +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 bulletin = new ArrayList<>(); + ArrayList forecastOne = new ArrayList<>(); + ArrayList forecastTwo = new ArrayList<>(); + ArrayList forecastThree = new ArrayList<>(); + Utilities utl = new Utilities(); + + ArrayList getForecast(String icaoCode, String key, int forecastId) { + ArrayList words = new ArrayList<>(); + 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 Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); + if (Response.statusCode() != 200) { + words.add("NO 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 : 0; + String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", JSONResponse.getJSONArray("dayOfWeek").getString(bump)).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 REPORT"); + return words; + } + } + + ArrayList getBulletin(String key, String lat, String lon) { + ArrayList words = new ArrayList<>(); + 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 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; + } + } + 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); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Main.java b/src/main/java/WS3000/weatherstar3000/Main.java new file mode 100644 index 0000000..0a02cc8 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Main.java @@ -0,0 +1,960 @@ +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 ldlList = new ArrayList<>(Arrays.asList("cityname", "condition", "temperature", "humidity", "pressure", "wind", "visibility", "precip")); + static boolean settingsErrorThrown = false; + static ArrayList 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 String todayMonth; + static String todayDay; + 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 nearNames = new ArrayList<>(); + static ArrayList nearIcaos = new ArrayList<>(); + static ArrayList regConNames = new ArrayList<>(); + static ArrayList regConIcaos = new ArrayList<>(); + static ArrayList regForNames = new ArrayList<>(); + static ArrayList regForIcaos = new ArrayList<>(); + static ArrayList tideIDs = new ArrayList<>(); + static ArrayList 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 + //tides + System.out.println("WeatherSTAR 3000 Simulator Version 1.5.0"); + + 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 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); + + almanac = new Almanac(); + todayMonth = almanac.getMonth(mainIcao, key); + todayDay = almanac.getDayDate(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 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 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 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"; + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/MouseListener.java b/src/main/java/WS3000/weatherstar3000/MouseListener.java new file mode 100644 index 0000000..ed71810 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/MouseListener.java @@ -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; + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Outlook.java b/src/main/java/WS3000/weatherstar3000/Outlook.java new file mode 100644 index 0000000..daf7240 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Outlook.java @@ -0,0 +1,35 @@ +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 outlook = new ArrayList<>(); + String getMonth() { + LocalDate cdate = LocalDate.now(); + Month cmonth = cdate.getMonth(); + + return cmonth.name().toUpperCase(); + } + ArrayList getOutlook() { + ArrayList outlook = new ArrayList<>(); + outlook.add("NO"); + outlook.add("REPORT"); + return outlook; + } + public void run() { + Main.outlook.month = getMonth(); + Main.outlook.outlook = getOutlook(); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/RegionalConditions.java b/src/main/java/WS3000/weatherstar3000/RegionalConditions.java new file mode 100644 index 0000000..a019e9c --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/RegionalConditions.java @@ -0,0 +1,76 @@ +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 locName = new ArrayList<>(); + ArrayList temperature = new ArrayList<>(); + ArrayList condition = new ArrayList<>(); + Utilities utl = new Utilities(); + + String getLocName(String displayName){ + return utl.ljust(displayName, 19, " ").substring(0, 19); + } + String getCondition(String icaoCode, String key) { + 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 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"; + } + } + String getTemperature(String icaoCode, String key) { + 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 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 " "; + } + } + public void run() { + ArrayList regConNames = new ArrayList<>(); + regConNames.addAll(Main.regConNames); + ArrayList regConIcaos = new ArrayList<>(); + regConIcaos.addAll(Main.regConIcaos); + String key = Main.key; + 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)); + } + } +} \ No newline at end of file diff --git a/src/main/java/WS3000/weatherstar3000/RegionalForecast.java b/src/main/java/WS3000/weatherstar3000/RegionalForecast.java new file mode 100644 index 0000000..34c2e35 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/RegionalForecast.java @@ -0,0 +1,108 @@ +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 RegionalForecast extends Thread { + ArrayList locName = new ArrayList<>(); + ArrayList condition = new ArrayList<>(); + ArrayList low = new ArrayList<>(); + ArrayList high = new ArrayList<>(); + Utilities utl = new Utilities(); + + String getLocName(String displayName){ + return utl.ljust(displayName, 14, " ").substring(0, 14); + } + String getCondition(String icaoCode, String key) { + 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 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"; + } + } + String getLow(String icaoCode, String key) { + 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 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 " "; + } + } + String getHigh(String icaoCode, String key) { + 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 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 " "; + } + } + public void run() { + ArrayList regForNames = new ArrayList<>(); + regForNames.addAll(Main.regForNames); + ArrayList 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)); + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Scene.java b/src/main/java/WS3000/weatherstar3000/Scene.java new file mode 100644 index 0000000..dcee04e --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Scene.java @@ -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 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; + } +} diff --git a/src/main/java/WS3000/weatherstar3000/SlidesRunner.java b/src/main/java/WS3000/weatherstar3000/SlidesRunner.java new file mode 100644 index 0000000..5b535c8 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/SlidesRunner.java @@ -0,0 +1,1406 @@ +package WS3000.weatherstar3000; + +import java.util.ArrayList; +import java.util.Objects; + +import javax.swing.ImageIcon; + +import org.joml.Vector2f; +import org.joml.Vector4f; + +import components.SpriteRenderer; +import components.Spritesheet; +import components.Sprite; +import util.AssetPool; +import util.Utilities; + +import static org.lwjgl.glfw.GLFW.*; + +import java.io.File; + +import java.awt.Color; +import java.awt.Image; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class SlidesRunner extends Scene { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mm:ss a"); + + 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(255.0f/255.0f, 255.0f/255.0f, 255.0f/255.0f, 1.0f); //white + Vector4f greenScreen = new Vector4f(0.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f, 1.0f); + Vector4f backgroundColor = color6; + + Spritesheet sprites; + GameObject bg; + GameObject dateBg; + GameObject ldl; + GameObject ldlBg; + GameObject travelBg; + + GameObject crawlBg; + GameObject cBumperOne; + GameObject cBumperTwo; + Utilities utl = new Utilities(); + + LocalDateTime now = LocalDateTime.now(); + ZonedDateTime today = ZonedDateTime.now(); + final String prefix = today.format(DateTimeFormatter.ofPattern("E MMM")); + + //slide line variables + ArrayList ccMainLines = new ArrayList<>(); + private GameObject[] ccPool = new GameObject[256]; + + ArrayList hoMainLines = new ArrayList<>(); + private GameObject[] hoPool = new GameObject[288]; + + ArrayList roMainLines = new ArrayList<>(); + private GameObject[] roPool = new GameObject[288]; + + ArrayList lfMainLines = new ArrayList<>(); + ArrayList lfbMainLines = new ArrayList<>(); + ArrayList forecastOneLines = new ArrayList<>(); + ArrayList forecastTwoLines = new ArrayList<>(); + ArrayList forecastThreeLines = new ArrayList<>(); + private GameObject[] lfhPool = new GameObject[32]; + private GameObject[] lfPool = new GameObject[288]; + + ArrayList alMainLines = new ArrayList<>(); + private GameObject[] alPool = new GameObject[288]; + + ArrayList rfMainLines = new ArrayList<>(); + private GameObject[] rfPool = new GameObject[288]; + + ArrayList efMainLines = new ArrayList<>(); + private GameObject[] efPool = new GameObject[288]; + + ArrayList olMainLines = new ArrayList<>(); + private GameObject[] olPool = new GameObject[288]; + + ArrayList tiMainLines = new ArrayList<>(); + private GameObject[] tiPool = new GameObject[288]; + + ArrayList travelMainLines = new ArrayList<>(); + private GameObject[] tfPool = new GameObject[864]; + + ArrayList bulletinMainLines = new ArrayList<>(); + ArrayList buPool = new ArrayList<>(); + + String dateLine = ""; + private GameObject[] dtPool = new GameObject[32]; + + ArrayList tickerLines = new ArrayList<>(); + private GameObject[] ctPool = new GameObject[32]; + + ArrayList acPool = new ArrayList<>(); + + static boolean slidesStarted = false; + + private boolean poolsInit = false; + private boolean slideInit = false; + + private int tinterval = 0; + + GameObject tBanner; + TravelForecast tfData; + float travelOffset = 0.0f; + boolean travelDataInit = false; + boolean travelForecastActive = false; + + Bulletin buData; + GameObject bulletinBg; + GameObject bulletinBanner; + boolean bulletinDataInit = false; + static boolean bulletinActive = false; + int bulletinOffset = 0; + Vector4f bulletinColor = new Vector4f(0.0f/255.0f, 255.0f/155.0f, 255.0f/255.0f, 1.0f); + float bulletinLength = 0.0f; + + static String ccType = ""; + + String crawlingText; + int crawlOffset = 0; + static boolean adCrawlActive = false; + float crawlLength = 0.0f; + + int ccIdx = 0; + int ccRounds = 0; + CurrentConditions tickerData = Main.currentConditions; + + float slideLength = 600.0f;//length in frames + int slideIdx = 0; + ArrayList slideLineup; + ArrayList slideDurations; + boolean loop; + boolean ending = false; + int slideRounds = 0; + int round = 0; + static boolean collectingData = false; + + static AudioManager audioManager; + + public SlidesRunner() { + ctData(); + } + + @Override + public void init() { + System.out.println("start slides loop"); + + crawlingText = Main.adCrawl + " "; + loop = Main.loopSlides; + + try { + slideLineup = utl.loadSegments(Main.selectedFlavor); + } catch (IOException e) { + System.err.println("Exception loading flavor segments"); + System.exit(100); + e.printStackTrace(); + } + + try { + slideDurations = utl.loadDurations(Main.selectedFlavor); + } catch (IOException e) { + System.err.println("Exception loading flavor durations"); + System.exit(101); + e.printStackTrace(); + } + + if (Main.greenScreen) { + backgroundColor = greenScreen; + } + + if (ccType == "crawl") { + adCrawlActive = true; + } else { + adCrawlActive = false; + } + + loadResources(); + this.camera = new Camera(new Vector2f(0, 0)); + + sprites = AssetPool.getSpritesheet("/resources/images/charMap.png"); + + bulletinBg = new GameObject("bulletinBg", new Transform(new Vector2f(0, 0), new Vector2f(720, 382)), 0); + bulletinBg.addComponent(new SpriteRenderer(color16)); + + + bulletinBanner = new GameObject("bulletinBanner", new Transform(new Vector2f(0, 0), new Vector2f(720, 42)), 0); + bulletinBanner.addComponent(new SpriteRenderer(color16)); + + initPools(); + + //Z INDICES: + //0 - SLIDES/TRAVEL/BULLETIN CRAWL + //2 - LOWERBAR + ldl = new GameObject("ldl", new Transform(new Vector2f(0, 380), new Vector2f(720, 2)), 0); + ldl.addComponent(new SpriteRenderer(color16)); + + dateBg = new GameObject("dateBg", new Transform(new Vector2f(0, 382), new Vector2f(720, 18)), 2); + dateBg.addComponent(new SpriteRenderer(backgroundColor)); + + ldlBg = new GameObject("ldlBg", new Transform(new Vector2f(0, 400), new Vector2f(720, 80)), 2); + ldlBg.addComponent(new SpriteRenderer(backgroundColor)); + + bg = new GameObject("bg", new Transform(new Vector2f(0, 0), new Vector2f(720, 380)), 0); + bg.addComponent(new SpriteRenderer(backgroundColor)); + + travelBg = new GameObject("travelBg", new Transform(new Vector2f(0, 0), new Vector2f(720, 380)), 0); + travelBg.addComponent(new SpriteRenderer(color1)); + + tBanner = new GameObject("travelBg", new Transform(new Vector2f(0, 0), new Vector2f(720, 42)), 0); + tBanner.addComponent(new SpriteRenderer(color1)); + + crawlBg = new GameObject("crawlBg", new Transform(new Vector2f(0, 382), new Vector2f(720, 98)), 2); + crawlBg.addComponent(new SpriteRenderer(backgroundColor)); + + cBumperOne = new GameObject("cBumperOne", new Transform(new Vector2f(0, 382), new Vector2f(109, 98)), 2); + cBumperOne.addComponent(new SpriteRenderer(backgroundColor)); + + cBumperTwo = new GameObject("cBumperTwo", new Transform(new Vector2f(634, 382), new Vector2f(86, 98)), 2); + cBumperTwo.addComponent(new SpriteRenderer(backgroundColor)); + + float x = (float) crawlingText.length()+1; + float crawlWidth = 17.5f * x; + crawlLength = 262.5f + (crawlWidth/2) + 2.0f; + + Window.slidesSecFrameCount = 0; + Window.secFrameCount = 0; + Window.fourSecFrameCount = 0; + Window.crawlSecFrameCount = 0; + Window.bTimerSecFrameCount = 0; + + audioManager = new AudioManager(Main.jarFolder + File.separator + "music" + File.separator); + audioManager.start(); + + slidesStarted = true; + } + + private void loadResources() { + AssetPool.getShader("/resources/shaders/default.glsl"); + + AssetPool.addSpritesheet("charMap.png", + new Spritesheet(AssetPool.getTexture("/resources/images/charMap.png"), + 32, 32, 128, 0)); + } + + private void initPools() { + if (poolsInit) return; + for (int i = 0; i < ccPool.length; i++) { + ccPool[i] = new GameObject("ccPool" + i, new Transform(new Vector2f()), 0); + ccPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < hoPool.length; i++) { + hoPool[i] = new GameObject("hoPool" + i, new Transform(new Vector2f()), 0); + hoPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < roPool.length; i++) { + roPool[i] = new GameObject("roPool" + i, new Transform(new Vector2f()), 0); + roPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < lfPool.length; i++) { + if (i < 32) { + lfhPool[i] = new GameObject("lfhPool" + i, new Transform(new Vector2f()), 0); + lfhPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + lfPool[i] = new GameObject("lfPool" + i, new Transform(new Vector2f()), 0); + lfPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < alPool.length; i++) { + alPool[i] = new GameObject("alPool" + i, new Transform(new Vector2f()), 0); + alPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < rfPool.length; i++) { + rfPool[i] = new GameObject("alPool" + i, new Transform(new Vector2f()), 0); + rfPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < efPool.length; i++) { + efPool[i] = new GameObject("alPool" + i, new Transform(new Vector2f()), 0); + efPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < olPool.length; i++) { + olPool[i] = new GameObject("alPool" + i, new Transform(new Vector2f()), 0); + olPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < tiPool.length; i++) { + tiPool[i] = new GameObject("tiPool" + i, new Transform(new Vector2f()), 0); + tiPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < tfPool.length; i++) { + tfPool[i] = new GameObject("tfPool" + i, new Transform(new Vector2f()), 0); + tfPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < dtPool.length; i++) { + dtPool[i] = new GameObject("dtPool" + i, new Transform(new Vector2f()), 2); + dtPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + for (int i = 0; i < ctPool.length; i++) { + ctPool[i] = new GameObject("ctPool" + i, new Transform(new Vector2f()), 2); + ctPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + + if (ccType != "obs") { + acPool.clear(); + for (int i = 0; i < crawlingText.length(); i++) { + acPool.add(new GameObject("acPool" + i, new Transform(new Vector2f()), 2)); + acPool.get(i).addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + } + } + + initBulPool(); + + poolsInit = true; + } + public void initBulPool() { + Bulletin bulletinData = Main.bulletin; + buPool.clear(); + if (bulletinData.bulletinText.get(1) != "NOBULLETINCRAWL") { + int j = 0; + for (int i = 1; i < bulletinData.bulletinText.size()-1; i++) { + for (int e = 0; e < bulletinData.bulletinText.get(i).length(); e++) { + buPool.add(new GameObject("buPool" + j, new Transform(new Vector2f()), 0)); + buPool.get(j).addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); + j++; + } + } + + try { + bulletinBg.getComponent(SpriteRenderer.class).setColor(utl.getBulletinColor(bulletinData.bulletinText.get(0))); + } catch (IOException e) { + bulletinBg.getComponent(SpriteRenderer.class).setColor(new Vector4f(0.0f, 0.0f, 0.0f, 1.0f)); + e.printStackTrace(); + } + + try { + bulletinBanner.getComponent(SpriteRenderer.class).setColor(utl.getBulletinColor(bulletinData.bulletinText.get(0))); + } catch (IOException e) { + bulletinBanner.getComponent(SpriteRenderer.class).setColor(new Vector4f(0.0f, 0.0f, 0.0f, 1.0f)); + e.printStackTrace(); + } + } + } + + @Override + public void update(float dt) { + //if (audioManager.isFinished()) { + // audioManager.start(); + //} + + this.gameObjects.clear(); + this.renderer.clear(); + + if (Window.secFrameCount >= 60) { + Window.secFrameCount = 0; + } + if (Window.fourSecFrameCount >= 240) { + Window.fourSecFrameCount = 0; + } + if (Window.slidesSecFrameCount >= slideLength) { + Window.slidesSecFrameCount = 0; + } + + if (Window.bTimerSecFrameCount >= 2700) { + Window.bTimerSecFrameCount = 0; + } + + if (Window.slidesSecFrameCount % slideLength == 0) { + travelForecastActive = false; + travelDataInit = false; + slideInit = false; + round++; + if (round >= slideRounds) { + slideIdx++; + if (slideIdx >= slideLineup.size()) { + slideIdx = 0; + if (!loop) { + ending = true; + } else { + DataRunner data = new DataRunner(); + if (!collectingData) { + collectingData = true; + ctData(); + data.start();//upon finish, collectingData will be turned false + //if (!bulletinActive) { + // initBulPool(); + //} + } + } + } + round = 0; + } + } + + if (ending && !bulletinActive) { + System.exit(0); + audioManager.close(); + //glfwSetWindowShouldClose(Window.getGLFWWindow(), true); + //Main.settingsWindow.setVisible(true); + } + + slideLength = slideDurations.get(slideIdx); + slideChooser(); + + if (travelForecastActive) { + if (Window.secFrameCount % 2 == 0) { + travelOffset--; + tinterval++; + if (tinterval == 3) { + travelOffset--; + tinterval = 0; + } + } + travelForecast(); + } + + //ldl + this.addGameObjectToScene(ldl); + + //update bulletin + if (!bulletinActive) { + if (Window.bTimerSecFrameCount == 0) { + if (Main.bulletin.bulletinText.get(1) != "NOBULLETINCRAWL") { + initBulPool(); + bulletinActive = true; + Window.bSlideSecFrameCount++; + bulletin(); + } else { + bulletinActive = false; + } + } + } else { + if (Window.bSlideSecFrameCount % bulletinLength == 0) { + //stop bulletin + bulletinActive = false; + bulletinDataInit = false; + Window.bTimerSecFrameCount = 0; + if (ending) { + System.exit(0); + audioManager.close(); + //glfwSetWindowShouldClose(Window.getGLFWWindow(), true); + //Main.settingsWindow.setVisible(true); + } + } else { + //continue bulletin + if (Window.secFrameCount % 2 == 0) bulletinOffset--; + Window.bSlideSecFrameCount++; + bulletin(); + } + } + + //lowerArea update + if (!adCrawlActive) { + if (Window.fourSecFrameCount % 240.0f == 0) { + if (ccRounds >= 1) { + ccRounds = 0; + toggleCrawl(); + } else { + ccTicker(true); + } + } + dateTime(); + ccTicker(false); + } else { + if (Window.crawlSecFrameCount >= crawlLength) { + toggleCrawl(); + Window.crawlSecFrameCount = 0; + } + crawlOffset -= 2; + adCrawl(); + } + + for (GameObject go : this.gameObjects) { + go.update(dt); + this.renderer.add(go); + } + + this.renderer.render(); + } + public void toggleCrawl() { + if (ccType == "obs") adCrawlActive = false; + if (ccType == "crawl") adCrawlActive = true; crawlOffset = 0; + if (ccType == "both") { + if (adCrawlActive) { + adCrawlActive = false; + } else { + adCrawlActive = true; crawlOffset = 0; + } + } + } + + public void adCrawl() { + this.addGameObjectToScene(crawlBg); + + int poolIdx = 0; + int textY = 382; + float textX = 634.0f + crawlOffset; + + for (int i = 0; i < crawlingText.length(); i++) { + if (poolIdx >= acPool.size()) break; + + if (textX > 91 && textX < 635) { + + char c = crawlingText.toUpperCase().charAt(i); + + GameObject go = acPool.get(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; + } + + this.addGameObjectToScene(cBumperOne); + this.addGameObjectToScene(cBumperTwo); + } + + public void dateTime() { + now = LocalDateTime.now(); + today = ZonedDateTime.now(); + + dateLine = utl.ljust(String.format("%s %2d", prefix, now.getDayOfMonth()).toUpperCase(), 10, " ") + utl.ljust(" ", 11, " ") + utl.rjust(now.format(formatter), 11, " "); + + this.addGameObjectToScene(dateBg); + + int textX = 81; + int textY = 382; + int poolIdx = 0; + + for (int i = 0; i < dateLine.length(); i ++) { + if (poolIdx >= dtPool.length) break; + + char c = dateLine.charAt(i); + + GameObject go = dtPool[poolIdx++]; + go.transform.position.set(textX, textY); + go.transform.scale.set(18, 32); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + sr.setSprite(sprites.getSprite(utl.getSmallChar(c))); + + this.addGameObjectToScene(go); + + if (i % 2 != 0) textX++; + textX += 17; + } + } + public void ccTicker(boolean advance) { + if (advance) { + ccIdx++; + if (ccIdx >= tickerLines.size()) { + ccIdx = 0; + ccRounds++; + } + } + + this.addGameObjectToScene(ldlBg); + int textX = 81; + int textY = 404; + int poolIdx = 0; + + String line = tickerLines.get(ccIdx); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= ctPool.length) break; + + char c = line.charAt(i); + + GameObject go = ctPool[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; + } + } + public void ctData() { + CurrentConditions ctData = Main.currentConditions; + + tickerLines.clear(); + tickerLines.add(utl.ljust(ctData.locName, 32, " ")); + tickerLines.add(utl.ljust(ctData.condition, 32, " ")); + tickerLines.add(utl.ljust(ctData.temperature + " " + ctData.feelsLike, 32, " ")); + tickerLines.add(utl.ljust(ctData.humidity + " " + ctData.dewPoint, 32, " ")); + tickerLines.add(utl.ljust(ctData.pressure, 32, " ")); + tickerLines.add(utl.ljust(ctData.wind + " " + ctData.gusts, 32, " ")); + tickerLines.add(utl.ljust(ctData.visibility + " " + ctData.ceiling, 32, " ")); + tickerLines.add(utl.ljust(ctData.precip, 32, " ")); + } + public void currentConditions() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + CurrentConditions ccData = Main.currentConditions; + + ccMainLines.clear(); + ccMainLines.add(utl.ljust(ccData.locName, 32, " ")); + ccMainLines.add(utl.ljust(ccData.condition, 32, " ")); + ccMainLines.add(utl.ljust(ccData.temperature + " " + ccData.feelsLike, 32, " ")); + ccMainLines.add(utl.ljust(ccData.humidity + " " + ccData.dewPoint, 32, " ")); + ccMainLines.add(utl.ljust(ccData.pressure, 32, " ")); + ccMainLines.add(utl.ljust(ccData.wind + " " + ccData.gusts, 32, " ")); + ccMainLines.add(utl.ljust(ccData.visibility + " " + ccData.ceiling, 32, " ")); + ccMainLines.add(utl.ljust(ccData.precip, 32, " ")); + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + int lineHeight = 40; + + for (int row = 0; row < ccMainLines.size(); row++) { + String line = ccMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= ccPool.length) break; + + char c = line.charAt(i); + + GameObject go = ccPool[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; + } + } + + public void hourlyObservations() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + HourlyObservations hoData = Main.hourlyObservations; + + hoMainLines.clear(); + hoMainLines.add(" LATEST HOURLY OBSERVATIONS "); + hoMainLines.add("LOCATION \\F WEATHER WIND"); + for (int i = 0; i < hoData.locName.size(); i++) { + hoMainLines.add(utl.ljust(hoData.locName.get(i), 14, " ") + utl.ljust(hoData.temperature.get(i), 3, " ") + " " + utl.ljust(hoData.condition.get(i), 10, " ") + hoData.wind.get(i)); + }; + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < hoMainLines.size(); row++) { + int lineHeight = row == 0 ? 38 : row == 1 ? 22 : 40; + String line = hoMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= hoPool.length) break; + + char c = line.charAt(i); + + GameObject go = hoPool[poolIdx++]; + go.transform.position.set(textX, textY); + go.transform.scale.set(18, 32); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + if (row == 1) {sr.setSprite(sprites.getSprite(utl.getSmallChar(c)));} else {sr.setSprite(sprites.getSprite(utl.getMainChar(c)));} + + + this.addGameObjectToScene(go); + + if (i % 2 != 0) textX++; + textX += 17; + } + + textX = 81; + textY += lineHeight; + } + } + + public void regionalConditions() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + RegionalConditions rcData = Main.regionalConditions; + + roMainLines.clear(); + roMainLines.add(" CONDITIONS ACROSS THE REGION "); + roMainLines.add("CITY WEATHER \\F"); + for (int i = 0; i < rcData.locName.size(); i++) { + roMainLines.add(utl.ljust(rcData.locName.get(i), 19, " ") + " " + utl.ljust(rcData.condition.get(i), 9, " ").substring(0, 9) + rcData.temperature.get(i)); + } + + slideInit = true; + } + + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < roMainLines.size(); row++) { + int lineHeight = row == 0 ? 38 : row == 1 ? 22 : 40; + String line = roMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= roPool.length) break; + + char c = line.charAt(i); + + GameObject go = roPool[poolIdx++]; + go.transform.position.set(textX, textY); + go.transform.scale.set(18, 32); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + if (row == 1) {sr.setSprite(sprites.getSprite(utl.getSmallChar(c)));} else {sr.setSprite(sprites.getSprite(utl.getMainChar(c)));} + + + this.addGameObjectToScene(go); + + if (i % 2 != 0) textX++; + textX += 17; + } + + textX = 81; + textY += lineHeight; + } + } + + public void localForecast() { + slideRounds = 3; + this.addGameObjectToScene(bg); + + if (!slideInit) { + LocalForecast lfData = Main.localForecast; + + lfMainLines.clear(); + lfbMainLines.clear(); + forecastOneLines.clear(); + forecastTwoLines.clear(); + forecastThreeLines.clear(); + + StringBuilder sb = new StringBuilder(); + + if (!lfData.bulletin.get(0).equals("NOBULLETIN")) { + for (int i = 0; i <= lfData.bulletin.size()-1; i++) { + if (lfData.bulletin.get(i).equals("*NEWLINE*")) { + lfbMainLines.add("*" + utl.cjust(sb.toString(), 30, " ") + "*"); + sb.setLength(0); + continue; + } + int wordlength = lfData.bulletin.get(i).length(); + if (wordlength + sb.length() + 1 <= 30) { + if (!sb.isEmpty()) {sb.append(" ");} + sb.append(lfData.bulletin.get(i)); + } else { + i--; + lfbMainLines.add("*" + utl.cjust(sb.toString(), 30, " ") + "*"); + sb.setLength(0); + } + } + lfbMainLines.add("*" + utl.cjust(sb.toString(), 30, " ") + "*"); + sb.setLength(0); + } else { + lfbMainLines.add("NOTHING"); + } + sb.setLength(0); + + for (int i = 0; i <= lfData.forecastOne.size()-1; i++) { + int wordlength = lfData.forecastOne.get(i).length(); + if (wordlength + sb.length() + 1 <= 32) { + if (!sb.isEmpty()) {sb.append(" ");} + sb.append(lfData.forecastOne.get(i)); + } else { + i--; + forecastOneLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + } + } + forecastOneLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + + for (int i = 0; i <= lfData.forecastTwo.size()-1; i++) { + int wordlength = lfData.forecastTwo.get(i).length(); + if (wordlength + sb.length() + 1 <= 32) { + if (!sb.isEmpty()) {sb.append(" ");} + sb.append(lfData.forecastTwo.get(i)); + } else { + i--; + forecastTwoLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + } + } + forecastTwoLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + + for (int i = 0; i <= lfData.forecastThree.size()-1; i++) { + int wordlength = lfData.forecastThree.get(i).length(); + if (wordlength + sb.length() + 1 <= 32) { + if (!sb.isEmpty()) {sb.append(" ");} + sb.append(lfData.forecastThree.get(i)); + } else { + i--; + forecastThreeLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + } + } + forecastThreeLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + + int linesPassed = 0; + + if (lfbMainLines.get(0).equals("NOTHING") && forecastOneLines.size() < 8) { + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + } else { + if (!lfbMainLines.get(0).equals("NOTHING")) { + for (int i = 0; i <= lfbMainLines.size()-1; i++) { + lfMainLines.add(lfbMainLines.get(i)); + linesPassed++; + } + } + + if (forecastOneLines.size() < 7 - linesPassed) { + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + } + } + + //then add first forecast + for (int i = 0; i <= forecastOneLines.size()-1; i++) { + lfMainLines.add(forecastOneLines.get(i)); + linesPassed++; + } + while (linesPassed < 8) { + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + } + + //next screen + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + for (int i = 0; i <= forecastTwoLines.size()-1; i++) { + lfMainLines.add(forecastTwoLines.get(i)); + linesPassed++; + } + while (linesPassed < 16) { + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + } + lfMainLines.add(utl.ljust("", 32, " ")); + for (int i = 0; i <= forecastThreeLines.size()-1; i++) { + lfMainLines.add(forecastThreeLines.get(i)); + linesPassed++; + } + while (linesPassed < 24) { + lfMainLines.add(utl.ljust("", 32, " ")); + linesPassed++; + } + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + String header = " YOUR TWC FORECAST "; + for (int i = 0; i < header.length(); i ++) { + if (poolIdx >= lfhPool.length) break; + + char c = header.charAt(i); + + GameObject go = lfhPool[poolIdx++]; + go.transform.position.set(textX, textY); + go.transform.scale.set(18, 32); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + sr.setSprite(sprites.getSprite(utl.getSmallChar(c))); + + this.addGameObjectToScene(go); + + if (i % 2 != 0) textX++; + textX += 17; + } + + poolIdx = 0; + textX = 81; + textY = 62; + + for (int row = 0; row < 8; row++) { + int lineHeight = 40; + String line = lfMainLines.get(row + (8*round)); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= lfPool.length) break; + + char c = line.charAt(i); + + GameObject go = lfPool[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; + } + } + + public void almanac() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + Almanac almanacData = Main.almanac; + + alMainLines.clear(); + + alMainLines.add(" THE WEATHER CHANNEL ALMANAC "); + alMainLines.add(utl.ljust("", 32, " "));//half space + alMainLines.add(utl.ljust(" " + almanacData.today + " " + almanacData.tomorrow, 32, " ")); + alMainLines.add(utl.ljust("SUNRISE " + almanacData.todaySunrise + " " + almanacData.tomorrowSunrise, 32, " ")); + alMainLines.add(utl.ljust("SUNSET " + almanacData.todaySunset + " " + almanacData.tomorrowSunset, 32, " ")); + alMainLines.add(utl.ljust("NORMAL LOW " + almanacData.todayLow + " " + almanacData.tomorrowLow, 32, " ")); + alMainLines.add(utl.ljust("NORMAL HIGH " + almanacData.todayHigh + " " + almanacData.tomorrowHigh, 32, " ")); + alMainLines.add(utl.ljust("", 32, " "));//half space + alMainLines.add(utl.ljust(Main.almanac.normalPrecip, 32, " ")); + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < alMainLines.size(); row++) { + int lineHeight = row == 1 || row == 7 ? 22 : 40; + String line = alMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= alPool.length) break; + + char c = line.charAt(i); + + GameObject go = alPool[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; + } + } + + public void regionalForecast() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + RegionalForecast rfData = Main.regionalForecast; + + rfMainLines.clear(); + + rfMainLines.add(" FORECAST ACROSS THE REGION "); + rfMainLines.add("CITY WEATHER LOW HI"); + for (int i = 0; i < rfData.locName.size(); i++) { + rfMainLines.add(utl.ljust(rfData.locName.get(i), 14, " ") + " " + utl.ljust(rfData.condition.get(i), 10, " ") + rfData.low.get(i) + " " + rfData.high.get(i)); + } + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < rfMainLines.size(); row++) { + int lineHeight = row == 0 ? 38 : row == 1 ? 22 : 40; + String line = rfMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= rfPool.length) break; + + char c = line.charAt(i); + + GameObject go = rfPool[poolIdx++]; + go.transform.position.set(textX, textY); + go.transform.scale.set(18, 32); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + if (row == 1) {sr.setSprite(sprites.getSprite(utl.getSmallChar(c)));} else {sr.setSprite(sprites.getSprite(utl.getMainChar(c)));} + + + this.addGameObjectToScene(go); + + if (i % 2 != 0) textX++; + textX += 17; + } + + textX = 81; + textY += lineHeight; + } + } + + public void extendedForecast() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + ExtendedForecast efData = Main.extendedForecast; + + efMainLines.clear(); + + efMainLines.add(" EXTENDED FORECAST "); + efMainLines.add(utl.ljust("", 32, " ")); + efMainLines.add(" " + efData.dayOne + " " + efData.dayTwo + " " + efData.dayThree); + efMainLines.add(" " + efData.conditionOne.get(0) + " " + efData.conditionTwo.get(0) + " " + efData.conditionThree.get(0)); + efMainLines.add(" " + efData.conditionOne.get(1) + " " + efData.conditionTwo.get(1) + " " + efData.conditionThree.get(1)); + efMainLines.add(utl.ljust("", 32, " ")); + efMainLines.add(" " + efData.lowOne + " " + efData.lowTwo + " " + efData.lowThree); + efMainLines.add(" " + efData.highOne + " " + efData.highTwo + " " + efData.highThree); + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < efMainLines.size(); row++) { + int lineHeight = 40; + String line = efMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= efPool.length) break; + + char c = line.charAt(i); + + GameObject go = efPool[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; + } + } + + public void outlook() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + Outlook oData = Main.outlook; + + olMainLines.clear(); + + olMainLines.add(" NAT'L WEATHER SERVICE OUTLOOK "); + olMainLines.add(utl.ljust(" ", 32, " "));//half space + olMainLines.add(utl.cjust(oData.month, 32, " ")); + olMainLines.add(utl.ljust(" ", 32, " ")); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i <= oData.outlook.size()-1; i++) { + int cwordlength = oData.outlook.get(i).length(); + if (cwordlength + sb.length() + 1 <= 32) { + if (!sb.isEmpty()) {sb.append(" ");} + sb.append(oData.outlook.get(i)); + } else { + i--; + olMainLines.add(utl.ljust(sb.toString(), 32, " ")); + sb.setLength(0); + } + } + olMainLines.add(utl.ljust(sb.toString(), 32, " ")); + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < olMainLines.size(); row++) { + int lineHeight = row == 1 ? 22 : 40; + String line = olMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= olPool.length) break; + + char c = line.charAt(i); + + GameObject go = olPool[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; + } + } + + public void tides() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + Tides tiData = Main.tides; + + tiMainLines.clear(); + + tiMainLines.add(" LOCAL TIDE INFORMATION "); + tiMainLines.add(utl.ljust(" ", 32, " "));//half space + tiMainLines.add(tiData.locName.get(0)); + tiMainLines.add("HIGHS: " + tiData.highTide.get(0)); + tiMainLines.add("LOWS: " + tiData.lowTide.get(0)); + tiMainLines.add(tiData.locName.get(1)); + tiMainLines.add("HIGHS: " + tiData.highTide.get(1)); + tiMainLines.add("LOWS: " + tiData.lowTide.get(1)); + tiMainLines.add(" SUNRISE" + tiData.sunrise + " SET" + tiData.sunset + " "); + + slideInit = true; + } + + int textX = 81; + int textY = 44; + int poolIdx = 0; + + for (int row = 0; row < tiMainLines.size(); row++) { + int lineHeight = row == 1 ? 22 : 40; + String line = tiMainLines.get(row); + for (int i = 0; i < line.length(); i ++) { + if (poolIdx >= tiPool.length) break; + + char c = line.charAt(i); + + GameObject go = tiPool[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; + } + } + + public void airQuality() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + slideInit = true; + } + } + + public void airportDelays() { + slideRounds = 0; + this.addGameObjectToScene(bg); + + if (!slideInit) { + slideInit = true; + } + } + + public void travelForecast() { + travelForecastActive = true; + this.addGameObjectToScene(travelBg); + + if (!travelDataInit) { + tfData = Main.travelForecast; + travelMainLines.clear(); + travelMainLines.add(" TRAVEL CITIES FORECAST "); + travelMainLines.add(utl.ljust(" ", 32, " ")); + travelMainLines.add("CITY WEATHER LOW HI"); + for (int i = 0; i < tfData.locName.size(); i++) { + travelMainLines.add(utl.ljust(tfData.locName.get(i), 15, " ") + + utl.ljust(tfData.condition.get(i), 10, " ") + + utl.rjust(tfData.low.get(i), 3, " ") + + utl.rjust(tfData.high.get(i), 4, " ")); + } + travelDataInit = true; + travelOffset = 0; + } + + float startY = 380 + travelOffset; + int poolIdx = 0; + + for (int row = 0; row < travelMainLines.size(); row++) { + int width = row == 0 ? 22 : 18; + int spacingX = row == 0 ? 23 : 17; + String line = travelMainLines.get(row); + float rowY = startY + (row * 60); + + if (rowY < -50 && rowY > 381) continue; + + int charX = 81; + for (int i = 0; i < line.length(); i++) { + if (poolIdx >= tfPool.length) break; + + if (rowY > -50 && rowY < 381) { + + char c = line.charAt(i); + + GameObject go = tfPool[poolIdx++]; + go.transform.position.set(charX, rowY); + go.transform.scale.set(width, 47); + + SpriteRenderer sr = go.getComponent(SpriteRenderer.class); + sr.setSprite(sprites.getSprite(utl.getMainChar(c))); + + this.addGameObjectToScene(go); + + if (i % 2 != 0) charX++; + charX += spacingX; + } + } + } + + this.addGameObjectToScene(tBanner); + } + + public void bulletin() { + bulletinActive = true; + + if (!bulletinDataInit) { + buData = Main.bulletin; + //try { + // bulletinBg.addComponent(new SpriteRenderer(utl.getBulletinColor(buData.bulletinText.get(0)))); + //} catch (IOException e) { + // bulletinBg.addComponent(new SpriteRenderer(new Vector4f(0.5f, 0.5f, 0.5f, 1.0f))); + // e.printStackTrace(); + //} + + bulletinMainLines.clear(); + + for (int i = 1; i < buData.bulletinText.size(); i++) { + bulletinMainLines.add(buData.bulletinText.get(i)); + } + + bulletinDataInit = true; + bulletinOffset = 0; + + float rows = (float) buData.bulletinText.size()-7; + bulletinLength = 764.0f + ((40.0f * rows)*2) + 2.0f;//length is an issue + } + + this.addGameObjectToScene(bulletinBg); + + float startY = 382 + bulletinOffset; + int poolIdx = 0; + + for (int row = 0; row < bulletinMainLines.size(); row++) { + String line = bulletinMainLines.get(row); + float rowY = startY + (row * 40); + + if (rowY < 0 && rowY > 383) continue; + + int charX = 81; + for (int i = 0; i < line.length(); i++) { + if (poolIdx >= buPool.size()) break; + + if (rowY > 0 && rowY < 383) { + + char c = line.charAt(i); + + GameObject go = buPool.get(poolIdx++); + go.transform.position.set(charX, rowY); + 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) charX++; + charX += 17; + } + } + } + + this.addGameObjectToScene(bulletinBanner); + } + + public void slideChooser() { + //draw slide + String slide = slideLineup.get(slideIdx); + //System.out.println(slide); + switch (slide) { + case "currentConditions": + currentConditions(); + break; + case "hourlyObservations": + hourlyObservations(); + break; + case "regionalConditions": + regionalConditions(); + break; + case "localForecast": + localForecast(); + break; + case "almanac": + if (Main.tidesEnabled) { + tides(); + } else { + almanac(); + } + break; + case "regionalForecast": + regionalForecast(); + break; + case "extendedForecast": + extendedForecast(); + break; + case "outlook": + outlook(); + break; + case "travelForecast": + travelForecast(); + break; + default: + System.out.println("Invalid product"); + System.exit(10); + audioManager.close(); + break; + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Tides.java b/src/main/java/WS3000/weatherstar3000/Tides.java new file mode 100644 index 0000000..755c2f3 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Tides.java @@ -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 locName = new ArrayList<>(); + ArrayList highTide = new ArrayList<>(); + ArrayList 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, " ").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 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 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 tideIDs = new ArrayList<>(); + tideIDs.addAll(Main.tideIDs); + ArrayList 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"); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Transform.java b/src/main/java/WS3000/weatherstar3000/Transform.java new file mode 100644 index 0000000..9a4f021 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Transform.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/WS3000/weatherstar3000/TravelForecast.java b/src/main/java/WS3000/weatherstar3000/TravelForecast.java new file mode 100644 index 0000000..63665c5 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/TravelForecast.java @@ -0,0 +1,104 @@ +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.JSONObject; + +import util.Utilities; + +public class TravelForecast extends Thread { + ArrayList locName = new ArrayList<>(); + ArrayList condition = new ArrayList<>(); + ArrayList low = new ArrayList<>(); + ArrayList high = new ArrayList<>(); + Utilities utl = new Utilities(); + + ArrayList 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 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, " ").substring(0, 14); + } + String getCondition(String icaoCode, String key) { + 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 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"; + } + } + String getLow(String icaoCode, String key) { + 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 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 " "; + } + } + String getHigh(String icaoCode, String key) { + 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 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 " "; + } + } + public void run() { + String key = Main.key; + 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)); + } + } +} diff --git a/src/main/java/WS3000/weatherstar3000/Window.java b/src/main/java/WS3000/weatherstar3000/Window.java new file mode 100644 index 0000000..2d62133 --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/Window.java @@ -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(); + } +} diff --git a/src/main/java/WS3000/weatherstar3000/WindowRunner.java b/src/main/java/WS3000/weatherstar3000/WindowRunner.java new file mode 100644 index 0000000..d04385f --- /dev/null +++ b/src/main/java/WS3000/weatherstar3000/WindowRunner.java @@ -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(); + } +} diff --git a/src/main/java/components/FontRenderer.java b/src/main/java/components/FontRenderer.java new file mode 100644 index 0000000..356fd52 --- /dev/null +++ b/src/main/java/components/FontRenderer.java @@ -0,0 +1,20 @@ +package components; + +import WS3000.weatherstar3000.Component; + +public class FontRenderer extends Component { + + + @Override + public void start() { + if (gameObject.getComponent(SpriteRenderer.class) != null) { + System.out.println("Found font renderer"); + } + } + + @Override + public void update(float dt) { + + } + +} diff --git a/src/main/java/components/Sprite.java b/src/main/java/components/Sprite.java new file mode 100644 index 0000000..80ec76d --- /dev/null +++ b/src/main/java/components/Sprite.java @@ -0,0 +1,34 @@ +package components; + +import org.joml.Vector2f; + +import renderer.Texture; + +public class Sprite { + private Texture texture; + private Vector2f[] texCoords; + + public Sprite(Texture texture) { + this.texture = texture; + Vector2f[] texCoords = { + new Vector2f(1,0), + new Vector2f(1,1), + new Vector2f(0,1), + new Vector2f(0,0) + }; + this.texCoords = texCoords; + } + + public Sprite(Texture texture, Vector2f[] texCoords) { + this.texture = texture; + this.texCoords = texCoords; + } + + public Texture getTexture() { + return this.texture; + } + + public Vector2f[] getTexCoords() { + return this.texCoords; + } +} diff --git a/src/main/java/components/SpriteRenderer.java b/src/main/java/components/SpriteRenderer.java new file mode 100644 index 0000000..cbf539c --- /dev/null +++ b/src/main/java/components/SpriteRenderer.java @@ -0,0 +1,73 @@ +package components; + +import WS3000.weatherstar3000.Component; +import WS3000.weatherstar3000.Transform; +import renderer.Texture; + +import org.joml.Vector2f; +import org.joml.Vector4f; + +public class SpriteRenderer extends Component { + private Vector4f color; + private Sprite sprite; + + private Transform lastTransform; + private boolean isDirty; + + public SpriteRenderer(Vector4f color) { + this.color = color; + this.sprite = new Sprite(null); + this.isDirty = true; + } + + public SpriteRenderer(Sprite sprite) { + this.sprite = sprite; + this.color = new Vector4f(1,1,1,1); + this.isDirty = true; + } + + @Override + public void start() { + this.lastTransform = gameObject.transform.copy(); + } + + @Override + public void update(float dt) { + if (!this.lastTransform.equals(this.gameObject.transform)) { + this.gameObject.transform.copy(lastTransform); + isDirty = true; + } + } + + public Vector4f getColor() { + return this.color; + } + + public Texture getTexture() { + return sprite.getTexture(); + } + + public Vector2f[] getTexCoords() { + return sprite.getTexCoords(); + } + + public void setSprite(Sprite sprite) { + this.sprite = sprite; + this.isDirty = true; + } + + public void setColor(Vector4f color) { + if (!this.color.equals(color)) { + this.isDirty = true; + this.color = color; + } + } + + public boolean isDirty() { + return this.isDirty; + } + + public void setClean() { + this.isDirty = false; + } +} diff --git a/src/main/java/components/Spritesheet.java b/src/main/java/components/Spritesheet.java new file mode 100644 index 0000000..fb7dba9 --- /dev/null +++ b/src/main/java/components/Spritesheet.java @@ -0,0 +1,46 @@ +package components; + +import java.util.ArrayList; +import java.util.List; + +import org.joml.Vector2f; + +import renderer.Texture; + +public class Spritesheet { + private Texture texture; + private List sprites; + + public Spritesheet(Texture texture, int spriteWidth, int spriteHeight, int numSprites, int spacing) { + this.sprites = new ArrayList<>(); + + this.texture = texture; + int currentX = 0; + int currentY = texture.getHeight() - spriteHeight; + for (int i = 0; i < numSprites; i++) { + float topY = (currentY + spriteHeight) / (float)texture.getHeight();; + float rightX = (currentX + spriteWidth) / (float)texture.getWidth(); + float leftX = currentX / (float)texture.getWidth(); + float bottomY = currentY / (float)texture.getHeight();; + + Vector2f[] texCoords = { + new Vector2f(rightX, bottomY), + new Vector2f(rightX, topY), + new Vector2f(leftX, topY), + new Vector2f(leftX, bottomY) + }; + Sprite sprite = new Sprite(this.texture, texCoords); + this.sprites.add(sprite); + + currentX += spriteWidth + spacing; + if (currentX >= texture.getWidth()) { + currentX = 0; + currentY -= spriteHeight + spacing; + } + } + } + + public Sprite getSprite(int index) { + return this.sprites.get(index); + } +} diff --git a/src/main/java/renderer/FrameBuffer.java b/src/main/java/renderer/FrameBuffer.java new file mode 100644 index 0000000..4a8e692 --- /dev/null +++ b/src/main/java/renderer/FrameBuffer.java @@ -0,0 +1,46 @@ +package renderer; + +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.*; + +public class FrameBuffer { + private int fboID = 0; + private Texture texture = null; + + public FrameBuffer(int width, int height) { + fboID = glGenFramebuffers(); + glBindFramebuffer(GL_FRAMEBUFFER, fboID); + + this.texture = new Texture(width, height); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this.texture.getId(), 0); + + int rboID = glGenRenderbuffers(); + glBindRenderbuffer(GL_RENDERBUFFER, rboID); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width, height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID); + + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + assert false : "Error: Framebuffer is not complete"; + } + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + public void bind() { + glBindFramebuffer(GL_FRAMEBUFFER, fboID); + } + + public void unbind() { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + public int getFboID() { + return fboID; + } + + public int getTextureId() { + return texture.getId(); + } +} diff --git a/src/main/java/renderer/RenderBatch.java b/src/main/java/renderer/RenderBatch.java new file mode 100644 index 0000000..ccf957b --- /dev/null +++ b/src/main/java/renderer/RenderBatch.java @@ -0,0 +1,242 @@ +package renderer; + +import components.SpriteRenderer; +import util.AssetPool; + +import static org.lwjgl.opengl.GL20.*; +import static org.lwjgl.opengl.GL30.*; + +import java.util.ArrayList; +import java.util.List; + +import org.joml.Vector2f; +import org.joml.Vector4f; + +import WS3000.weatherstar3000.Window; + +public class RenderBatch implements Comparable { + private final int POS_SIZE = 2; + private final int COLOR_SIZE = 4; + private final int TEX_COORDS_SIZE = 2; + private final int TEX_ID_SIZE = 1; + + private final int POS_OFFSET = 0; + private final int COLOR_OFFSET = POS_OFFSET + (POS_SIZE * Float.BYTES); + private final int TEX_COORDS_OFFSET = COLOR_OFFSET + (COLOR_SIZE * Float.BYTES); + private final int TEX_ID_OFFSET = TEX_COORDS_OFFSET + (TEX_COORDS_SIZE * Float.BYTES); + + private final int VERTEX_SIZE = 9; + private final int VERTEX_SIZE_BYTES = VERTEX_SIZE * Float.BYTES; + + private SpriteRenderer[] sprites; + private int numSprites; + private boolean hasRoom; + private float[] vertices; + private int[] texSlots = {0,1,2,3,4,5,6,7}; + + private List textures; + private int vaoID, vboID; + private int maxBatchSize; + private Shader shader; + private int zIndex; + + public RenderBatch(int maxBatchSize, int zIndex) { + this.zIndex = zIndex; + shader = AssetPool.getShader("/resources/shaders/default.glsl"); + shader.compile(); + this.sprites = new SpriteRenderer[maxBatchSize]; + this.maxBatchSize = maxBatchSize; + + vertices = new float[maxBatchSize * 4 * VERTEX_SIZE]; + + this.numSprites = 0; + this.hasRoom = true; + this.textures = new ArrayList<>(); + } + + public void start() { + vaoID = glGenVertexArrays(); + glBindVertexArray(vaoID); + + vboID = glGenBuffers(); + glBindBuffer(GL_ARRAY_BUFFER, vboID); + glBufferData(GL_ARRAY_BUFFER, vertices.length * Float.BYTES, GL_DYNAMIC_DRAW); + + int eboID = glGenBuffers(); + int[] indices = generateIndices(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eboID); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW); + + glVertexAttribPointer(0, POS_SIZE, GL_FLOAT, false, VERTEX_SIZE_BYTES, POS_OFFSET); + glEnableVertexAttribArray(0); + + glVertexAttribPointer(1, COLOR_SIZE, GL_FLOAT, false, VERTEX_SIZE_BYTES, COLOR_OFFSET); + glEnableVertexAttribArray(1); + + glVertexAttribPointer(2, TEX_COORDS_SIZE, GL_FLOAT, false, VERTEX_SIZE_BYTES, TEX_COORDS_OFFSET); + glEnableVertexAttribArray(2); + + glVertexAttribPointer(3, TEX_ID_SIZE, GL_FLOAT, false, VERTEX_SIZE_BYTES, TEX_ID_OFFSET); + glEnableVertexAttribArray(3); + } + + public void addSprite(SpriteRenderer spr) { + int index = this.numSprites; + this.sprites[index] = spr; + this.numSprites++; + + if (spr.getTexture() != null) { + if (!textures.contains(spr.getTexture())) { + textures.add(spr.getTexture()); + } + } + + loadVertexProperties(index); + + if (numSprites >= this.maxBatchSize) { + this.hasRoom = false; + } + } + + public void render() { + boolean rebufferData = false; + for (int i = 0; i < numSprites; i++) { + SpriteRenderer spr = sprites[i]; + if (spr.isDirty()) { + loadVertexProperties(i); + spr.setClean(); + rebufferData = true; + } + } + + if (rebufferData) { + glBindBuffer(GL_ARRAY_BUFFER, vboID); + glBufferSubData(GL_ARRAY_BUFFER, 0, vertices); + } + + shader.use(); + shader.uploadMat4f("uProjection", Window.getScene().camera().getProjectionMatrix()); + shader.uploadMat4f("uView", Window.getScene().camera().getViewMatrix()); + + for (int i = 0; i < textures.size(); i++) { + glActiveTexture(GL_TEXTURE0 + i + 1); + textures.get(i).bind(); + } + + shader.uploadIntArray("uTextures", texSlots); + + glBindVertexArray(vaoID); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glEnableVertexAttribArray(3); + + glDrawElements(GL_TRIANGLES, this.numSprites * 6, GL_UNSIGNED_INT, 0); + + glDisableVertexAttribArray(0); + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(2); + glDisableVertexAttribArray(3); + glBindVertexArray(0); + + for (int i = 0; i < textures.size(); i++) { + textures.get(i).unBind(); + } + + shader.detach(); + } + + private void loadVertexProperties(int index) { + SpriteRenderer sprite = this.sprites[index]; + + int offset = index * 4 * VERTEX_SIZE; + + Vector4f color = sprite.getColor(); + Vector2f[] texCoords = sprite.getTexCoords(); + + int texId = 0; + + if (sprite.getTexture() != null) { + for (int i = 0; i < textures.size(); i++) { + if (textures.get(i).equals(sprite.getTexture())) { + texId = i + 1; + break; + } + } + } + + float xAdd = 1.0f; + float yAdd = 1.0f; + for (int i = 0; i < 4; i++) { + if (i == 1) { + yAdd = 0.0f; + } else if (i == 2) { + xAdd = 0.0f; + } else if (i == 3) { + yAdd = 1.0f; + } + + vertices[offset] = sprite.gameObject.transform.position.x + (xAdd * sprite.gameObject.transform.scale.x); + vertices[offset + 1] = sprite.gameObject.transform.position.y + (yAdd * sprite.gameObject.transform.scale.y); + + vertices[offset + 2] = color.x; + vertices[offset + 3] = color.y; + vertices[offset + 4] = color.z; + vertices[offset + 5] = color.w; + + vertices[offset + 6] = texCoords[i].x; + vertices[offset + 7] = texCoords[i].y; + + vertices[offset + 8] = texId;; + + offset += VERTEX_SIZE; + } + } + + private int[] generateIndices() { + int[] elements = new int [6 * maxBatchSize]; + for (int i = 0; i < maxBatchSize; i++) { + loadElementIndices(elements, i); + } + + return elements; + } + + private void loadElementIndices(int[] elements, int index) { + int offsetArrayIndex = 6 * index; + int offset = 4 * index; + + elements[offsetArrayIndex] = offset + 3; + elements[offsetArrayIndex + 1] = offset + 2; + elements[offsetArrayIndex + 2] = offset + 0; + + elements[offsetArrayIndex + 3] = offset + 0; + elements[offsetArrayIndex + 4] = offset + 2; + elements[offsetArrayIndex + 5] = offset + 1; + } + + public boolean hasRoom() { + return this.hasRoom; + } + + public boolean hasTextureRoom() { + return this.textures.size() < 8; + } + + public boolean hasTexture(Texture tex) { + return this.textures.contains(tex); + } + + public int zIndex() { + return this.zIndex; + } + + public void clear() { + this.numSprites = 0; + } + + @Override + public int compareTo(RenderBatch o) { + return Integer.compare(this.zIndex, o.zIndex()); + } +} diff --git a/src/main/java/renderer/Renderer.java b/src/main/java/renderer/Renderer.java new file mode 100644 index 0000000..2305f21 --- /dev/null +++ b/src/main/java/renderer/Renderer.java @@ -0,0 +1,60 @@ +package renderer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import WS3000.weatherstar3000.GameObject; +import components.SpriteRenderer; + +public class Renderer { + private final int MAX_BATCH_SIZE = 2500; + private List batches; + + public Renderer() { + this.batches = new ArrayList<>(); + + } + + public void add(GameObject go) { + SpriteRenderer spr = go.getComponent(SpriteRenderer.class); + if (spr != null) { + add(spr); + } + } + + private void add(SpriteRenderer sprite) { + boolean added = false; + for (RenderBatch batch : batches) { + if (batch.hasRoom() && batch.zIndex() == sprite.gameObject.zIndex()) { + Texture tex = sprite.getTexture(); + if (tex == null || (batch.hasTexture(tex) || batch.hasTextureRoom())) { + batch.addSprite(sprite); + added = true; + break; + } + } + } + + if (!added) { + RenderBatch newBatch = new RenderBatch(MAX_BATCH_SIZE, sprite.gameObject.zIndex()); + newBatch.start(); + batches.add(newBatch); + newBatch.addSprite(sprite); + Collections.sort(batches); + } + } + + public void render() { + for (RenderBatch batch : batches) { + batch.render(); + } + } + + public void clear() { + for (RenderBatch batch : batches) { + batch.clear(); // Resets numSprites to 0 + } + //this.batches.clear(); + } +} diff --git a/src/main/java/renderer/Shader.java b/src/main/java/renderer/Shader.java new file mode 100644 index 0000000..e1c4de2 --- /dev/null +++ b/src/main/java/renderer/Shader.java @@ -0,0 +1,183 @@ +package renderer; + +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL20.*; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.FloatBuffer; +import java.nio.file.*; +import java.util.stream.Collectors; + +import org.joml.*; +import org.lwjgl.BufferUtils; + +public class Shader { + private int shaderProgramID; + private boolean beingUsed = false; + private String vertexSource; + private String fragmentSource; + private String filepath; + + public Shader(String filepath) { + this.filepath = filepath; + try { + // Make sure the path starts with a leading slash for root JAR loading + String resourcePath = filepath.startsWith("/") ? filepath : "/" + filepath; + + String source; + try (InputStream is = Shader.class.getResourceAsStream(resourcePath)) { + if (is == null) { + throw new IOException("Shader file not found inside JAR: " + resourcePath); + } + // Safely read all text lines into a single String + source = new BufferedReader(new InputStreamReader(is)) + .lines().collect(Collectors.joining("\n")); + } + + String[] splitString = source.split("(#type)( )+([a-zA-Z]+)"); + + int index = source.indexOf("#type") + 6; + int eol = source.indexOf("\n", index); + String firstPattern = source.substring(index, eol).trim(); + + index = source.indexOf("#type", eol) + 6; + eol = source.indexOf("\n", index); + String secondPattern = source.substring(index, eol).trim(); + + if (firstPattern.equals("vertex")) { + vertexSource = splitString[1]; + } else if (firstPattern.equals("fragment")) { + fragmentSource = splitString[1]; + } else { + throw new IOException("Unexpected token '" + firstPattern + "'"); + } + + if (secondPattern.equals("vertex")) { + vertexSource = splitString[2]; + } else if (secondPattern.equals("fragment")) { + fragmentSource = splitString[2]; + } else { + throw new IOException("Unexpected token '" + secondPattern + "'"); + } + } catch (IOException e) { + e.printStackTrace(); + assert false : "ERROR: Could not open file for shader: " + filepath; + } + } + + + public void compile() { + int vertexID, fragmentID; + vertexID = glCreateShader(GL_VERTEX_SHADER); + + glShaderSource(vertexID, vertexSource); + glCompileShader(vertexID); + + int success = glGetShaderi(vertexID, GL_COMPILE_STATUS); + if (success == GL_FALSE) { + int len = glGetShaderi(vertexID, GL_INFO_LOG_LENGTH); + System.out.println("ERROR: " + filepath + "\n\tVertex shader compilation failed."); + System.out.println(glGetShaderInfoLog(vertexID, len)); + assert false : ""; + } + + fragmentID = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource(fragmentID, fragmentSource); + glCompileShader(fragmentID); + + success = glGetShaderi(fragmentID, GL_COMPILE_STATUS); + if (success == GL_FALSE) { + int len = glGetShaderi(fragmentID, GL_INFO_LOG_LENGTH); + System.out.println("ERROR: " + filepath + "\n\tVertex shader compilation failed."); + System.out.println(glGetShaderInfoLog(fragmentID, len)); + assert false : ""; + } + + shaderProgramID = glCreateProgram(); + glAttachShader(shaderProgramID, vertexID); + glAttachShader(shaderProgramID, fragmentID); + glLinkProgram(shaderProgramID); + + success = glGetProgrami(shaderProgramID, GL_LINK_STATUS); + if (success == GL_FALSE) { + int len = glGetProgrami(shaderProgramID, GL_LINK_STATUS); + System.out.println("ERROR: " + filepath + "\n\tFailed to link shaders."); + System.out.println(glGetProgramInfoLog(shaderProgramID, len)); + assert false : ""; + } + } + + public void use() { + if (!beingUsed) { + glUseProgram(shaderProgramID); + beingUsed = true; + } + } + + public void detach() { + glUseProgram(0); + beingUsed = false; + } + + public void uploadMat4f(String varName, Matrix4f mat4) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + FloatBuffer matBuffer = BufferUtils.createFloatBuffer(16); + mat4.get(matBuffer); + glUniformMatrix4fv(varLocation, false, matBuffer); + } + + public void uploadMat3f(String varName, Matrix3f mat3) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + FloatBuffer matBuffer = BufferUtils.createFloatBuffer(9); + mat3.get(matBuffer); + glUniformMatrix3fv(varLocation, false, matBuffer); + } + + public void uploadVec4f(String varName, Vector4f vec) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform4f(varLocation, vec.x, vec.y, vec.z, vec.w); + } + + public void uploadVec3f(String varName, Vector3f vec) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform3f(varLocation, vec.x, vec.y, vec.z); + } + + public void uploadVec2f(String varName, Vector2f vec) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform2f(varLocation, vec.x, vec.y); + } + + public void uploadFloat(String varName, float val) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform1f(varLocation, val); + } + + public void uploadInt(String varName, int val) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform1i(varLocation, val); + } + + public void uploadTexture(String varName, int slot) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform1i(varLocation, slot); + } + + public void uploadIntArray(String varName, int[] array) { + int varLocation = glGetUniformLocation(shaderProgramID, varName); + use(); + glUniform1iv(varLocation, array); + } +} diff --git a/src/main/java/renderer/Texture.java b/src/main/java/renderer/Texture.java new file mode 100644 index 0000000..8150afd --- /dev/null +++ b/src/main/java/renderer/Texture.java @@ -0,0 +1,126 @@ +package renderer; + +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.ARBTextureRectangle.*; + +import static org.lwjgl.stb.STBImage.*; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.*; + +import org.lwjgl.BufferUtils; + +public class Texture { + private String filepath; + private int texID; + private int width, height; + + public Texture() { + texID = -1; + width = -1; + height = -1; + } + + public Texture(int width, int height) { + this.filepath = "Generated"; + + texID = glGenTextures(); + glBindTexture(GL_TEXTURE_2D, texID); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); + } + + public Texture(String filepath) { + this.filepath = filepath; + + texID = glGenTextures(); + glBindTexture(GL_TEXTURE_2D, texID); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + IntBuffer widthBuffer = BufferUtils.createIntBuffer(1); + IntBuffer heightBuffer = BufferUtils.createIntBuffer(1); + IntBuffer channelsBuffer = BufferUtils.createIntBuffer(1); + + stbi_set_flip_vertically_on_load(true); + + // Ensure the path starts with a leading slash for classpath lookup + String resourcePath = filepath.startsWith("/") ? filepath : "/" + filepath; + ByteBuffer image = null; + + try (InputStream is = Texture.class.getResourceAsStream(resourcePath)) { + if (is == null) { + throw new IOException("Texture file not found inside JAR: " + resourcePath); + } + + // Read bytes from the JAR stream into a native ByteBuffer + byte[] bytes = is.readAllBytes(); + ByteBuffer nativeBuffer = BufferUtils.createByteBuffer(bytes.length); + nativeBuffer.put(bytes); + nativeBuffer.flip(); + + // Tell STB to decode the image from raw memory instead of a disk path + image = stbi_load_from_memory(nativeBuffer, widthBuffer, heightBuffer, channelsBuffer, 0); + } catch (IOException e) { + e.printStackTrace(); + assert false : "ERROR: Could not read stream for texture: " + filepath; + } + + if (image != null) { + this.width = widthBuffer.get(0); + this.height = heightBuffer.get(0); + int channels = channelsBuffer.get(0); + + if (channels == 3) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this.width, this.height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); + } else if (channels == 4) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); + } else { + stbi_image_free(image); + assert false : "ERROR: (Texture) Unknown number of channels " + channels + ", " + filepath; + } + stbi_image_free(image); + } else { + assert false : "ERROR: STB failed to decode image " + filepath + " Reason: " + stbi_failure_reason(); + } + } + + public void bind() { + glBindTexture(GL_TEXTURE_2D, texID); + } + + public void unBind() { + glBindTexture(GL_TEXTURE_2D, 0); + } + + public int getWidth() { + return this.width; + } + + public String getFilePath() { + return this.filepath; + } + + public int getHeight() { + return this.height; + } + + public int getId() { + return this.texID; + } + + @Override + public boolean equals(Object o) { + if (o == null) return false; + if (!(o instanceof Texture)) return false; + Texture oTex = (Texture) o; + return oTex.getWidth() == this.width && oTex.getHeight() == this.height && oTex.getId() == this.texID && oTex.getFilePath().equals(this.filepath); + } +} diff --git a/src/main/java/util/AssetPool.java b/src/main/java/util/AssetPool.java new file mode 100644 index 0000000..13b6d23 --- /dev/null +++ b/src/main/java/util/AssetPool.java @@ -0,0 +1,49 @@ +package util; +import renderer.Shader; +import renderer.Texture; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import components.Spritesheet; + +public class AssetPool { + private static Map shaders = new HashMap<>(); + private static Map textures = new HashMap<>(); + private static Map spritesheets = new HashMap<>(); + + public static Shader getShader(String resourceName) { + if (AssetPool.shaders.containsKey(resourceName)) { + return AssetPool.shaders.get(resourceName); + } else { + Shader shader = new Shader(resourceName); + shader.compile(); + AssetPool.shaders.put(resourceName, shader); + return shader; + } + } + + public static Texture getTexture(String resourceName) { + if (AssetPool.textures.containsKey(resourceName)) { + return AssetPool.textures.get(resourceName); + } else { + Texture texture = new Texture(resourceName); + AssetPool.textures.put(resourceName, texture); + return texture; + } + } + + public static void addSpritesheet(String resourceName, Spritesheet spritesheet) { + if (!AssetPool.spritesheets.containsKey(resourceName)) { + AssetPool.spritesheets.put(resourceName, spritesheet); + } + } + + public static Spritesheet getSpritesheet(String resourceName) { + if (!AssetPool.spritesheets.containsKey(resourceName)) { + assert false : "Error: Tried to access spritesheet '" + resourceName + "' and it has not been added to the asset pool."; + } + return AssetPool.spritesheets.getOrDefault(resourceName, null); + } +} diff --git a/src/main/java/util/Utilities.java b/src/main/java/util/Utilities.java new file mode 100644 index 0000000..e1a6dcd --- /dev/null +++ b/src/main/java/util/Utilities.java @@ -0,0 +1,416 @@ +package util; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import org.json.*; +import org.joml.Vector4f; + +public class Utilities { + public static Map mainFontMap = new HashMap<>(); + public static Map smallFontMap = new HashMap<>(); + + static { + mainFontMap.put(' ', 0); + mainFontMap.put('!', 1); + mainFontMap.put('"', 2); + mainFontMap.put('#', 3); + mainFontMap.put('$', 4); + mainFontMap.put('%', 5); + mainFontMap.put('&', 6); + mainFontMap.put('\'', 7); + mainFontMap.put('(', 8); + mainFontMap.put(')', 9); + mainFontMap.put('*', 10); + mainFontMap.put('+', 11); + mainFontMap.put(',', 12); + mainFontMap.put('-', 13); + mainFontMap.put('.', 14); + mainFontMap.put('/', 15); + mainFontMap.put('0', 16); + mainFontMap.put('1', 17); + mainFontMap.put('2', 18); + mainFontMap.put('3', 19); + mainFontMap.put('4', 20); + mainFontMap.put('5', 21); + mainFontMap.put('6', 22); + mainFontMap.put('7', 23); + mainFontMap.put('8', 24); + mainFontMap.put('9', 25); + mainFontMap.put(':', 26); + mainFontMap.put(';', 27); + mainFontMap.put('<', 28); + mainFontMap.put('=', 29); + mainFontMap.put('>', 30); + mainFontMap.put('?', 31); + mainFontMap.put('@', 64); + mainFontMap.put('A', 65); + mainFontMap.put('B', 66); + mainFontMap.put('C', 67); + mainFontMap.put('D', 68); + mainFontMap.put('E', 69); + mainFontMap.put('F', 70); + mainFontMap.put('G', 71); + mainFontMap.put('H', 72); + mainFontMap.put('I', 73); + mainFontMap.put('J', 74); + mainFontMap.put('K', 75); + mainFontMap.put('L', 76); + mainFontMap.put('M', 77); + mainFontMap.put('N', 78); + mainFontMap.put('O', 79); + mainFontMap.put('P', 80); + mainFontMap.put('Q', 81); + mainFontMap.put('R', 82); + mainFontMap.put('S', 83); + mainFontMap.put('T', 84); + mainFontMap.put('U', 85); + mainFontMap.put('V', 86); + mainFontMap.put('W', 87); + mainFontMap.put('X', 88); + mainFontMap.put('Y', 89); + mainFontMap.put('Z', 90); + mainFontMap.put('[', 91); + mainFontMap.put('\\', 92); + mainFontMap.put(']', 93); + mainFontMap.put('^', 94); + mainFontMap.put('_', 95); + mainFontMap.put('`', 96); + + smallFontMap.put(' ', 32); + smallFontMap.put('!', 33); + smallFontMap.put('"', 34); + smallFontMap.put('#', 35); + smallFontMap.put('$', 36); + smallFontMap.put('%', 37); + smallFontMap.put('&', 38); + smallFontMap.put('\'', 39); + smallFontMap.put('(', 40); + smallFontMap.put(')', 41); + smallFontMap.put('*', 42); + smallFontMap.put('+', 43); + smallFontMap.put(',', 44); + smallFontMap.put('-', 45); + smallFontMap.put('.', 46); + smallFontMap.put('/', 47); + smallFontMap.put('0', 48); + smallFontMap.put('1', 49); + smallFontMap.put('2', 50); + smallFontMap.put('3', 51); + smallFontMap.put('4', 52); + smallFontMap.put('5', 53); + smallFontMap.put('6', 54); + smallFontMap.put('7', 55); + smallFontMap.put('8', 56); + smallFontMap.put('9', 57); + smallFontMap.put(':', 58); + smallFontMap.put(';', 59); + smallFontMap.put('<', 60); + smallFontMap.put('=', 61); + smallFontMap.put('>', 62); + smallFontMap.put('?', 63); + smallFontMap.put('A', 97); + smallFontMap.put('B', 98); + smallFontMap.put('C', 99); + smallFontMap.put('D', 100); + smallFontMap.put('E', 101); + smallFontMap.put('F', 102); + smallFontMap.put('G', 103); + smallFontMap.put('H', 104); + smallFontMap.put('I', 105); + smallFontMap.put('J', 106); + smallFontMap.put('K', 107); + smallFontMap.put('L', 108); + smallFontMap.put('M', 109); + smallFontMap.put('N', 110); + smallFontMap.put('O', 111); + smallFontMap.put('P', 112); + smallFontMap.put('Q', 113); + smallFontMap.put('R', 114); + smallFontMap.put('S', 115); + smallFontMap.put('T', 116); + smallFontMap.put('U', 117); + smallFontMap.put('V', 118); + smallFontMap.put('W', 119); + smallFontMap.put('X', 120); + smallFontMap.put('Y', 121); + smallFontMap.put('Z', 122); + smallFontMap.put('[', 123); + smallFontMap.put('\\', 124); + smallFontMap.put(']', 125); + smallFontMap.put('^', 126); + smallFontMap.put('`', 127); + smallFontMap.put('_', 128); + } + + public int getMainChar(char character) { + return mainFontMap.get(character); + } + + public int getSmallChar(char character) { + return smallFontMap.get(character); + } + + public String ljust(String s, int width, String fillChar) { + if (s.length() >= width) { + return s; + } + StringBuilder sb = new StringBuilder(s); + while (sb.length() < width) { + sb.append(fillChar); + } + return sb.toString(); + } + + public String rjust(String s, int width, String fillChar) { + if (s.length() >= width) { + return s; + } + StringBuilder sb = new StringBuilder(); + while (sb.length() < width - s.length()) { + sb.append(fillChar); + } + sb.append(s); + return sb.toString(); + } + + public String cjust(String s, int width, String fillChar) { + if (s.length() >= width) { + return s; // No centering needed if text is already too long + } + int padding = width - s.length(); + int leftPadding = padding / 2; + int rightPadding = padding - leftPadding; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < leftPadding; i++) { + sb.append(fillChar); + } + sb.append(s); + for(int i = 0; i < rightPadding; i++) { + sb.append(fillChar); + } + return sb.toString(); + } + + public String degToThreeLetter(int windDir) { + if (windDir >= 0 && windDir <= 11.25) { + return "N "; + } else if (windDir > 11.25 && windDir <= 33.75) { + return "NNE"; + } else if (windDir > 33.75 && windDir <= 56.25) { + return "NE "; + } else if (windDir > 56.25 && windDir <= 78.75) { + return "ENE"; + } else if (windDir > 78.75 && windDir <= 101.25) { + return "E "; + } else if (windDir > 101.25 && windDir <= 123.75) { + return "ESE"; + } else if (windDir > 123.75 && windDir <= 146.25) { + return "SE "; + } else if (windDir > 146.25 && windDir <= 168.75) { + return "SSE"; + } else if (windDir > 168.75 && windDir <= 191.25) { + return "S "; + } else if (windDir > 191.25 && windDir <= 213.75) { + return "SSW"; + } else if (windDir > 213.75 && windDir <= 236.25) { + return "SW "; + } else if (windDir > 236.25 && windDir <= 258.75) { + return "WSW"; + } else if (windDir > 258.75 && windDir <= 281.25) { + return "W "; + } else if (windDir > 281.25 && windDir <= 303.75) { + return "WNW"; + } else if (windDir > 303.75 && windDir <= 326.25) { + return "NW "; + } else if (windDir > 326.25 && windDir <= 348.75) { + return "NNW"; + } else if (windDir > 348.75 && windDir <= 360) { + return "N "; + } else { + return " "; + } + } + + public String degToTwoLetter(int windDir) { + if (windDir >= 0 && windDir <= 22.5) { + return "N "; + } else if (windDir > 22.5 && windDir <= 67.5) { + return "NE"; + } else if (windDir > 67.5 && windDir <= 112.5) { + return "E "; + } else if (windDir > 112.5 && windDir <= 157.5) { + return "SE"; + } else if (windDir > 157.5 && windDir <= 202.5) { + return "S "; + } else if (windDir > 202.5 && windDir <= 247.5) { + return "SW"; + } else if (windDir > 247.5 && windDir <= 292.5) { + return "W "; + } else if (windDir > 292.5 && windDir <= 337.5) { + return "NW"; + } else if (windDir > 337.5 && windDir <= 360) { + return "N "; + } else { + return " "; + } + } + + public String degToOneLetter(int windDir) { + if (windDir >= 0 && windDir <= 45) { + return "N"; + } else if (windDir > 45 && windDir <= 135) { + return "E"; + } else if (windDir > 135 && windDir <= 225) { + return "S"; + } else if (windDir > 225 && windDir <= 315) { + return "W"; + } else if (windDir > 315 && windDir <= 360) { + return "N"; + } else { + return " "; + } + } + + public String formatWind(int windSpeed, int windDir, boolean spaced) { + String spacer = ""; + String ending = ""; + int speedLength = Integer.toString(windSpeed).length(); + if (spaced) {spacer = " "; ending = " MPH";} + if (windSpeed == 0) {return "CALM";} + if (speedLength == 1) { + return degToThreeLetter(windDir) + spacer + windSpeed + ending; + } else if (speedLength == 2) { + return degToTwoLetter(windDir) + spacer + windSpeed + ending; + } else if (speedLength == 3) { + return degToOneLetter(windDir) + spacer + windSpeed + ending; + } else { + return " " + spacer + ending; + } + } + + public String formatShortCond(String condition) { + String conditionFinal = condition; + if (conditionFinal.contains("EARLY")) { + conditionFinal = "AM " + conditionFinal.replaceAll("EARLY", ""); + } + if (conditionFinal.contains("LATE")) { + conditionFinal = "PM " + conditionFinal.replaceAll("LATE", ""); + } + return conditionFinal.replaceAll(" SHOWER", " SHWR").replaceAll("NEAR", "").replaceAll("LIGHT", "LGT").replaceAll("HEAVY", "HVY").replaceAll("PARTIAL", "PART").replaceAll("CLDY", "CLOUDY").replaceAll(" T-STORM", " T-STM").replaceAll("SHOWERS/", "SHWRS/"); + } + + private String readJsonFromResource(String path) throws IOException { + StringBuilder jsonText = new StringBuilder(); + + try (InputStream is = getClass().getResourceAsStream(path)) { + if (is == null) { + throw new IOException("Resource not found inside JAR: " + path); + } + try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { + String line; + while ((line = br.readLine()) != null) { + jsonText.append(line).append("\n"); + } + } + } + return jsonText.toString(); + } + + public String getCondition(int iconCode) throws IOException { + String json = readJsonFromResource("/resources/json/ObsMapping.json"); + return new JSONObject(json).getString(Integer.toString(iconCode)).toUpperCase(); + } + + public String getForecast(int iconCode) throws IOException { + String json = readJsonFromResource("/resources/json/FcstMapping.json"); + return new JSONObject(json).getString(Integer.toString(iconCode)).toUpperCase(); + } + + public String getForecastEx(int iconCode, int lineNum) throws IOException { + String json = readJsonFromResource("/resources/json/FcstTwoLineMapping.json"); + return ljust(new JSONObject(json).getJSONArray(Integer.toString(iconCode)).getString(lineNum).toUpperCase(), 10, " "); + } + + public boolean isHeadline(String headline) throws IOException { + String json = readJsonFromResource("/resources/json/AlertMapping.json"); + JSONObject jsonObject = new JSONObject(json); + + if (jsonObject.has(headline)) { + return jsonObject.getJSONObject(headline).getBoolean("headline"); + } else { + return false; + } + } + + public boolean isScroll(String headline) throws IOException { + String json = readJsonFromResource("/resources/json/AlertMapping.json"); + JSONObject jsonObject = new JSONObject(json); + + if (jsonObject.has(headline)) { + return jsonObject.getJSONObject(headline).getBoolean("scroll"); + } else { + return false; + } + } + + public String getSeverity(String headline) throws IOException { + String json = readJsonFromResource("/resources/json/AlertMapping.json"); + JSONObject jsonObject = new JSONObject(json); + + if (jsonObject.has(headline)) { + return jsonObject.getJSONObject(headline).getString("severity"); + } else { + return "None"; + } + } + + public Vector4f getBulletinColor(String headline) throws IOException { + if (getSeverity(headline).equals("Warning")) { + return new Vector4f(104.0f/255.0f, 0.0f/255.0f, 8.0f/255.0f, 1.0f); + } else if (getSeverity(headline).equals("Advisory")) { + return new Vector4f(160.0f/255.0f, 78.0f/255.0f, 14.0f/255.0f, 1.0f); + } else { + return new Vector4f(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); + } + } + + public void printThirtyTwoLine() { + System.out.println("--------------------------------"); + } + + public ArrayList loadSegments(String flavor) throws IOException { + String json = readJsonFromResource("/resources/json/SlidesManager.json"); + JSONObject jsonObject = new JSONObject(json); + + JSONArray fl = jsonObject.getJSONArray(flavor); + + ArrayList segments = new ArrayList<>(); + + for (int i = 0; i < fl.length(); i++) { + segments.add(fl.getJSONObject(i).getString("segment")); + } + + return segments; + } + + public ArrayList loadDurations(String flavor) throws IOException { + String json = readJsonFromResource("/resources/json/SlidesManager.json"); + JSONObject jsonObject = new JSONObject(json); + + JSONArray fl = jsonObject.getJSONArray(flavor); + + ArrayList segments = new ArrayList<>(); + + for (int i = 0; i < fl.length(); i++) { + segments.add(fl.getJSONObject(i).getFloat("duration")); + } + + return segments; + } +} \ No newline at end of file diff --git a/src/main/resources/images/charMap.png b/src/main/resources/images/charMap.png new file mode 100644 index 0000000..b0e87ae Binary files /dev/null and b/src/main/resources/images/charMap.png differ diff --git a/src/main/resources/images/icon.png b/src/main/resources/images/icon.png new file mode 100644 index 0000000..169fc40 Binary files /dev/null and b/src/main/resources/images/icon.png differ diff --git a/src/main/resources/json/AlertMapping.json b/src/main/resources/json/AlertMapping.json new file mode 100644 index 0000000..a1981a2 --- /dev/null +++ b/src/main/resources/json/AlertMapping.json @@ -0,0 +1,45 @@ +{ + "Avalanche Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Avalanche Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Avalanche Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Blizzard Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Blizzard Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Winter Weather Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Winter Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Winter Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Ice Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Freeze Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Freeze Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Frost Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Cold Weather Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Extreme Cold Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Snow Squall Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Fire Weather Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Red Flag Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Dense Fog Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "High Wind Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "High Wind Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Wind Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Severe Thunderstorm Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Severe Thunderstorm Warning": { "headline": false, "scroll": true, "severity": "Warning" }, + "Tornado Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Tornado Warning": { "headline": false, "scroll": true, "severity": "Warning" }, + "Extreme Wind Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Blowing Dust Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Ashfall Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Dust Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Earthquake Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Flood Watch": { "headline": false, "scroll": true, "severity": "Advisory" }, + "Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" }, + "Coastal Flood Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Coastal Flood Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Coastal Flood Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Flash Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" }, + "Excessive Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Excessive Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Heat Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Tropical Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Tropical Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" }, + "Hurricane Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, + "Hurricane Warning": { "headline": true, "scroll": true, "severity": "Warning" } +} \ No newline at end of file diff --git a/src/main/resources/json/FcstMapping.json b/src/main/resources/json/FcstMapping.json new file mode 100644 index 0000000..6efc8fe --- /dev/null +++ b/src/main/resources/json/FcstMapping.json @@ -0,0 +1,301 @@ +{ + "300": "Strg T'Stm", + "310": "Strg T'Stm", + "400": "T'Storms", + "402": "Hvy T'Stm", + "410": "T'Stms/Wnd", + "412": "Hvy T'Stm", + "500": "Rain/Snow", + "510": "Rain/Snow", + "600": "Rain/Sleet", + "601": "Lgt Rn/Slt", + "610": "Rain/Sleet", + "611": "Lgt Rn/Slt", + "700": "Wintry Mix", + "701": "Lgt Mix", + "710": "Wnt Mx/Wnd", + "711": "Lgt Mx/Wnd", + "800": "Frz Rain", + "810": "Frz Rain", + "850": "Frz Rain", + "900": "Lgt Rain", + "910": "Lgt Rn/Wnd", + "950": "Lgt Rain", + "1000": "Frz Rain", + "1001": "Lgt Frz Rn", + "1002": "Hvy Frz Rn", + "1010": "Frz Rain", + "1011": "Lgt Frz Rn", + "1012": "Hvy Frz Rn", + "1051": "Lgt Frz Rn", + "1100": "Showers", + "1110": "Shwrs/Wnd", + "1140": "T'Shwrs", + "1170": "T'Shwrs", + "1200": "Rain", + "1201": "Lgt Rain", + "1210": "Rain/Wind", + "1211": "Lgt Rain", + "1240": "Rain/Thndr", + "1251": "Lgt Rain", + "1270": "Rain/Wind", + "1300": "Flurries", + "1310": "Flurries", + "1400": "Snow Shwrs", + "1410": "Snow Shwrs", + "1600": "Snow", + "1601": "Lgt Snow", + "1610": "Snow/Wind", + "1611": "Snow/Wind", + "1651": "Lgt Snow", + "1800": "Sleet", + "1801": "Lgt Sleet", + "1810": "Sleet/Wind", + "1811": "Lgt Sleet", + "2000": "Fog", + "2010": "Fog/Wind", + "2100": "Hazy", + "2110": "Hazy/Wind", + "2600": "Cloudy", + "2610": "Cldy/Wnd", + "2700": "M Cloudy", + "2710": "M Cldy/Wnd", + "2800": "M Cloudy", + "2810": "M Cldy/Wnd", + "2900": "P Cloudy", + "2910": "P Cldy/Wnd", + "3000": "P Cloudy", + "3010": "P Cldy/Wnd", + "3100": "Clear", + "3110": "Clr/Wind", + "3200": "Sunny", + "3210": "Sun/Wind", + "3300": "M Clear", + "3310": "M Clr/Wnd", + "3400": "M Sunny", + "3410": "M Sun/Wnd", + "3700": "Iso T'stms", + "3709": "Iso T'stms", + "3710": "Iso T'stms", + "3719": "Iso T'stms", + "3800": "Sct T'stms", + "3809": "Sct T'stms", + "3810": "Sct T'stms", + "3819": "Sct T'stms", + "3900": "Sct Shwrs", + "3909": "Sct Shwrs", + "3910": "Shwrs/Wnd", + "3919": "Shwrs/Wnd", + "4000": "Heavy Rain", + "4010": "Heavy Rain", + "4100": "Snow Shwrs", + "4109": "Snow Shwrs", + "4110": "Snow Shwrs", + "4119": "Snow Shwrs", + "4200": "Heavy Snow", + "4210": "Heavy Snow", + "4300": "Blizzard", + "4400": "???", + "4500": "Sprinkles", + "4510": "Sprnk/Wnd", + "4600": "Few Shwrs", + "4610": "Shwrs/Wnd", + "4700": "Snow Shwrs", + "4710": "Snow Shwrs", + "4800": "Flurries", + "4809": "Flurries", + "4810": "Flurries", + "4819": "Flurries", + "4900": "Rain/Snow", + "4910": "Rain/Snow", + "5000": "Blw Snow", + "5100": "Frz Rn/Slt", + "5101": "Frz Rn/Slt", + "5110": "Frz Rn/Slt", + "5111": "Lgt Frz Rn", + "5200": "Snow/Sleet", + "5210": "Snow/Sleet", + "5300": "Frz Rain", + "5301": "Lgt Frz Rn", + "5302": "Hvy Frz Rn", + "5310": "Frz Rain", + "5311": "Lgt Frz Rn", + "5312": "Hvy Frz Rn", + "5351": "Lgt Frz Rn", + "5400": "Snw Squall", + "5409": "Snw Squall", + "5500": "Squalls", + "5509": "Squalls", + "5600": "T'Snow", + "5610": "T'Snow", + "5700": "Strg T'stm", + "5709": "Strg T'stm", + "5710": "Strg T'stm", + "5719": "Strg T'stm", + "6000": "AM Drizzle", + "6003": "AM Drizzle", + "6010": "AM Drizzle", + "6013": "AM Drizzle", + "6100": "AM Showers", + "6103": "AM Showers", + "6110": "Shwrs/Wnd", + "6113": "AM Showers", + "6140": "AM T'Shwrs", + "6143": "AM T'Shwrs", + "6170": "T'Shwrs", + "6173": "AM T'Shwrs", + "6200": "AM T'Storm", + "6203": "AM T'Storm", + "6210": "AM T'Storm", + "6213": "AM T'Storm", + "6300": "AM Rain", + "6301": "AM Rain", + "6303": "AM Rain", + "6304": "AM Lgt Rn", + "6310": "Rain/Wind", + "6311": "Rain/Wind", + "6313": "AM Rn/Wnd", + "6314": "AM Rn/Wnd", + "6400": "AM Rn/Snw", + "6401": "AM Rn/Snw", + "6403": "AM Rn/Snw", + "6404": "AM Rn/Snw", + "6410": "AM Rn/Snw", + "6411": "AM Rn/Snw", + "6413": "AM Rn/Snw", + "6414": "AM Rn/Snw", + "6500": "Rain/Ice", + "6501": "Rain/Ice", + "6503": "AM Rn/Ice", + "6504": "AM Rn/Ice", + "6510": "Rain/Ice", + "6511": "Rain/Ice", + "6513": "AM Rn/Ice", + "6514": "AM Rn/Ice", + "6600": "AM Ice", + "6603": "AM Ice", + "6610": "AM Ice", + "6613": "AM Ice/Wnd", + "6700": "AM Mix", + "6701": "AM Mix", + "6703": "AM Mix", + "6704": "AM Mix/Wnd", + "6710": "AM Mix", + "6711": "AM Mix", + "6713": "AM Mix/Wnd", + "6714": "AM Mix/Wnd", + "6800": "Snow Shwrs", + "6803": "AM Snow", + "6810": "Snow Shwrs", + "6813": "AM Snw/Wnd", + "6900": "AM Snow", + "6901": "Lgt Snow", + "6903": "AM Snow", + "6904": "AM Lgt Snw", + "6910": "AM Snow", + "6911": "AM Snow", + "6913": "AM Snw/Wnd", + "6914": "AM Lgt Snw", + "7000": "PM Drizzle", + "7003": "PM Drizzle", + "7010": "PM Drizzle", + "7013": "PM Drizzle", + "7100": "PM Showers", + "7103": "PM Showers", + "7110": "Shwrs/Wnd", + "7113": "PM Showers", + "7140": "T'Shwrs", + "7143": "PM T'Shwrs", + "7170": "T'Shwrs", + "7173": "T'Shwrs", + "7200": "T'Storms", + "7203": "PM T'Storm", + "7210": "T'Storms", + "7213": "PM T'Storm", + "7300": "PM Rain", + "7301": "PM Rain", + "7303": "PM Rain", + "7304": "PM Lgt Rn", + "7310": "Rain/Wind", + "7311": "Rain/Wind", + "7313": "PM Rn/Wnd", + "7314": "PM Rn/Wnd", + "7400": "PM Rn/Snw", + "7401": "PM Rn/Snw", + "7403": "PM Rn/Snw", + "7404": "PM Rn/Snw", + "7410": "PM Rn/Snw", + "7411": "PM Rn/Snw", + "7413": "PM Rn/Snw", + "7414": "PM Rn/Snw", + "7500": "Rain/Ice", + "7501": "Rain/Ice", + "7503": "PM Rn/Ice", + "7504": "PM Rn/Ice", + "7510": "Rain/Ice", + "7511": "Rain/Ice", + "7513": "PM Rn/Ice", + "7514": "PM Rn/Ice", + "7600": "PM Ice", + "7603": "PM Ice", + "7610": "PM Ice/Wnd", + "7613": "PM Ice/Wnd", + "7700": "PM Mix", + "7701": "PM Mix", + "7703": "PM Mix", + "7704": "PM Mix", + "7710": "PM Mix", + "7711": "PM Mix", + "7713": "PM Mix/Wnd", + "7714": "PM Mix/Wnd", + "7800": "Snow Shwrs", + "7803": "PM Snow", + "7810": "Snow Shwrs", + "7813": "PM Snow", + "7900": "PM Snow", + "7901": "Lgt Snow", + "7903": "PM Snow", + "7904": "PM Lgt Snw", + "7910": "PM Snow", + "7911": "Lgt Snow", + "7913": "PM Snw/Wnd", + "7914": "PM Lgt Snw", + "8000": "Rain/Snow", + "8010": "Rain/Snow", + "8100": "Rain/Ice", + "8110": "Rain/Ice", + "8200": "Snow/Rain", + "8210": "Snow/Rain", + "8300": "Mix/Rain", + "8310": "Mix/Rain", + "8400": "Snow/Ice", + "8410": "Snow/Ice", + "8500": "Ice/Rain", + "8510": "Ice/Rain", + "8600": "Ice/Snow", + "8610": "Ice/Snow", + "8700": "Mix/Snow", + "8710": "Mix/Snow", + "8800": "Snow/Mix", + "8810": "Snow/Mix", + "8900": "Mix/Rain", + "8910": "Mix/Rain", + "9000": "PM Clear", + "9003": "AM Clouds", + "9010": "Clear/Wnd", + "9013": "P Cldy/Wnd", + "9100": "AM Fog", + "9103": "AM Fog", + "9110": "AM Fog", + "9113": "AM Fog", + "9200": "AM Fog", + "9203": "AM Fog", + "9210": "AM Fog", + "9213": "AM Fog", + "9300": "PM Fog", + "9303": "PM Fog", + "9310": "PM Fog/Wnd", + "9313": "PM Fog", + "9500": "Rain/Mix", + "9510": "Rain/Mix" +} \ No newline at end of file diff --git a/src/main/resources/json/FcstTwoLineMapping.json b/src/main/resources/json/FcstTwoLineMapping.json new file mode 100644 index 0000000..2987aa4 --- /dev/null +++ b/src/main/resources/json/FcstTwoLineMapping.json @@ -0,0 +1,1198 @@ +{ + "300": [ + "Strong", + "Storms" + ], + "310": [ + "Strong", + "Storms" + ], + "400": [ + "T'Storms", + "" + ], + "402": [ + "Heavy", + "T'Storms" + ], + "410": [ + "T'Storms", + "Wind" + ], + "412": [ + "Heavy", + "T'Storms" + ], + "500": [ + "Rain", + "Snow" + ], + "510": [ + "Rain/Snow", + "Wind" + ], + "600": [ + "Rain", + "Sleet" + ], + "601": [ + "Light Rain", + "Sleet" + ], + "610": [ + "Rain/Sleet", + "Wind" + ], + "611": [ + "Light Rain", + "Sleet/Wind" + ], + "700": [ + "Wintry", + "Mix" + ], + "701": [ + "Light", + "Wintry Mix" + ], + "710": [ + "Wintry Mix", + "Wind" + ], + "711": [ + "Lgt Wintry", + "Mix/Wind" + ], + "800": [ + "Freezing", + "Drizzle" + ], + "810": [ + "Freezing", + "Drizzle" + ], + "850": [ + "Freezing", + "Drizzle" + ], + "900": [ + "Drizzle", + "" + ], + "910": [ + "Drizzle", + "Wind" + ], + "950": [ + "Drizzle", + "Fog" + ], + "1000": [ + "Freezing", + "Rain" + ], + "1001": [ + "Light Frz", + "Rain" + ], + "1002": [ + "Heavy Frz", + "Rain" + ], + "1010": [ + "Freezing", + "Rain/Wind" + ], + "1011": [ + "Light Frz", + "Rain/Wind" + ], + "1012": [ + "Heavy Frz", + "Rain/Wind" + ], + "1051": [ + "Light Frz", + "Rain/Fog" + ], + "1100": [ + "Showers", + "" + ], + "1110": [ + "Showers", + "Wind" + ], + "1140": [ + "T'Showers", + "" + ], + "1170": [ + "T'Showers", + "Wind" + ], + "1200": [ + "Rain", + "" + ], + "1201": [ + "Light", + "Rain" + ], + "1210": [ + "Rain", + "Wind" + ], + "1211": [ + "Light Rain", + "Wind" + ], + "1240": [ + "Rain", + "Thunder" + ], + "1251": [ + "Light Rain", + "Fog" + ], + "1270": [ + "Rain/Wind", + "Thunder" + ], + "1300": [ + "Flurries", + "" + ], + "1310": [ + "Flurries", + "Wind" + ], + "1400": [ + "Snow", + "Showers" + ], + "1410": [ + "Snow", + "Showers" + ], + "1600": [ + "Snow", + "" + ], + "1601": [ + "Light", + "Snow" + ], + "1610": [ + "Snow", + "Wind" + ], + "1611": [ + "Light Snow", + "Wind" + ], + "1651": [ + "Light Snow", + "Fog" + ], + "1800": [ + "Sleet", + "" + ], + "1801": [ + "Light", + "Sleet" + ], + "1810": [ + "Sleet", + "Wind" + ], + "1811": [ + "Lgt Sleet", + "Wind" + ], + "2000": [ + "Foggy", + "" + ], + "2010": [ + "Foggy", + "Wind" + ], + "2100": [ + "Hazy", + "" + ], + "2110": [ + "Hazy", + "Wind" + ], + "2600": [ + "Cloudy", + "" + ], + "2610": [ + "Cloudy", + "Wind" + ], + "2700": [ + "Mostly", + "Cloudy" + ], + "2710": [ + "M Cloudy", + "Wind" + ], + "2800": [ + "Mostly", + "Cloudy" + ], + "2810": [ + "M Cloudy", + "Wind" + ], + "2900": [ + "Partly", + "Cloudy" + ], + "2910": [ + "P Cloudy", + "Wind" + ], + "3000": [ + "Partly", + "Cloudy" + ], + "3010": [ + "P Cloudy", + "Wind" + ], + "3100": [ + "Clear", + "" + ], + "3110": [ + "Clear", + "Wind" + ], + "3200": [ + "Sunny", + "" + ], + "3210": [ + "Sunny", + "Wind" + ], + "3300": [ + "Mostly", + "Clear" + ], + "3310": [ + "M Clear", + "Wind" + ], + "3400": [ + "Mostly", + "Sunny" + ], + "3410": [ + "M Sunny", + "Wind" + ], + "3700": [ + "Isolated", + "T'Storms" + ], + "3709": [ + "Isolated", + "T'Storms" + ], + "3710": [ + "Isolated", + "T'Storms" + ], + "3719": [ + "Isolated", + "T'Storms" + ], + "3800": [ + "Scattered", + "T'Storms" + ], + "3809": [ + "Scattered", + "T'Storms" + ], + "3810": [ + "Scattered", + "T'Storms" + ], + "3819": [ + "Scattered", + "T'Storms" + ], + "3900": [ + "Scattered", + "Showers" + ], + "3909": [ + "Scattered", + "Showers" + ], + "3910": [ + "Scattered", + "Showers" + ], + "3919": [ + "Scattered", + "Showers" + ], + "4000": [ + "Heavy", + "Rain" + ], + "4010": [ + "Heavy", + "Rain/Wind" + ], + "4100": [ + "Sct Snow", + "Showers" + ], + "4109": [ + "Sct Snow", + "Showers" + ], + "4110": [ + "Snow", + "Showers" + ], + "4119": [ + "Snow", + "Showers" + ], + "4200": [ + "Heavy", + "Snow" + ], + "4210": [ + "Heavy", + "Snow/Wind" + ], + "4300": [ + "Blizzard", + "" + ], + "4400": [ + "???", + "" + ], + "4500": [ + "Sprinkles", + "" + ], + "4510": [ + "Sprinkles", + "Wind" + ], + "4600": [ + "Few", + "Showers" + ], + "4610": [ + "Few", + "Showers" + ], + "4700": [ + "Few Snow", + "Showers" + ], + "4710": [ + "Few Snow", + "Showers" + ], + "4800": [ + "Scattered", + "Flurries" + ], + "4809": [ + "Scattered", + "Flurries" + ], + "4810": [ + "Scattered", + "Flurries" + ], + "4819": [ + "Scattered", + "Flurries" + ], + "4900": [ + "Rain/Snow", + "Showers" + ], + "4910": [ + "Rain/Snow", + "Wind" + ], + "5000": [ + "Snow", + "Wind" + ], + "5100": [ + "Freezing", + "Rain/Sleet" + ], + "5101": [ + "Freezing", + "Rain/Sleet" + ], + "5110": [ + "Frz Rain", + "Sleet/Wind" + ], + "5111": [ + "Frz Rain", + "Sleet/Wind" + ], + "5200": [ + "Snow", + "Sleet" + ], + "5210": [ + "Snow", + "Sleet/Wind" + ], + "5300": [ + "Rain", + "Frz Rain" + ], + "5301": [ + "Light Rain", + "Frz Rain" + ], + "5302": [ + "Heavy Rain", + "Frz Rain" + ], + "5310": [ + "Rain/Ice", + "Wind" + ], + "5311": [ + "Light Rain", + "Ice/Wind" + ], + "5312": [ + "Heavy Rain", + "Ice/Wind" + ], + "5351": [ + "Light Rain", + "Frz Rain" + ], + "5400": [ + "Snow", + "Squalls" + ], + "5409": [ + "Snow", + "Squalls" + ], + "5500": [ + "Rain", + "Squalls" + ], + "5509": [ + "Rain", + "Squalls" + ], + "5600": [ + "Thunder", + "Snow" + ], + "5610": [ + "T'Snow", + "Wind" + ], + "5700": [ + "Sct Strong", + "Storms" + ], + "5709": [ + "Sct Strong", + "Storms" + ], + "5710": [ + "Sct Strong", + "Storms" + ], + "5719": [ + "Sct Strong", + "Storms" + ], + "6000": [ + "AM", + "Drizzle" + ], + "6003": [ + "AM", + "Drizzle" + ], + "6010": [ + "AM", + "Drizzle" + ], + "6013": [ + "AM Drizzle", + "Wind" + ], + "6100": [ + "AM", + "Showers" + ], + "6103": [ + "AM", + "Showers" + ], + "6110": [ + "Showers", + "Wind" + ], + "6113": [ + "AM", + "Showers" + ], + "6140": [ + "AM", + "T'Showers" + ], + "6143": [ + "AM", + "T'Showers" + ], + "6170": [ + "AM", + "T'Showers" + ], + "6173": [ + "AM", + "T'Showers" + ], + "6200": [ + "AM", + "T'Storms" + ], + "6203": [ + "AM", + "T'Storms" + ], + "6210": [ + "AM", + "T'Storms" + ], + "6213": [ + "AM", + "T'Storms" + ], + "6300": [ + "AM", + "Rain" + ], + "6301": [ + "AM", + "Lgt Rain" + ], + "6303": [ + "AM", + "Rain" + ], + "6304": [ + "AM Light", + "Rain" + ], + "6310": [ + "AM Rain", + "Wind" + ], + "6311": [ + "AM Light", + "Rain/Wind" + ], + "6313": [ + "AM Rain", + "Wind" + ], + "6314": [ + "AM Rain", + "Wind" + ], + "6400": [ + "AM", + "Rain/Snow" + ], + "6401": [ + "Rain/Snow", + "Showers" + ], + "6403": [ + "AM", + "Rain/Snow" + ], + "6404": [ + "AM", + "Rain/Snow" + ], + "6410": [ + "AM Rain", + "Snow/Wind" + ], + "6411": [ + "AM Rain", + "Snow/Wind" + ], + "6413": [ + "AM", + "Rain/Snow" + ], + "6414": [ + "AM", + "Rain/Snow" + ], + "6500": [ + "AM Rain", + "Ice" + ], + "6501": [ + "AM Light", + "Rain/Ice" + ], + "6503": [ + "AM Rain", + "Ice" + ], + "6504": [ + "AM Rain", + "Ice" + ], + "6510": [ + "AM Rain", + "Ice/Wind" + ], + "6511": [ + "Light Rain", + "Ice/Wind" + ], + "6513": [ + "AM Rain", + "Ice/Wind" + ], + "6514": [ + "AM Rain", + "Ice/Wind" + ], + "6600": [ + "AM", + "Ice" + ], + "6603": [ + "AM", + "Ice" + ], + "6610": [ + "AM", + "Ice/Wind" + ], + "6613": [ + "AM", + "Ice/Wind" + ], + "6700": [ + "AM Wintry", + "Mix" + ], + "6701": [ + "AM Wintry", + "Mix" + ], + "6703": [ + "AM", + "Wintry Mix" + ], + "6704": [ + "AM Light", + "Wintry Mix" + ], + "6710": [ + "AM Wintry", + "Mix/Wind" + ], + "6711": [ + "AM Wintry", + "Mix/Wind" + ], + "6713": [ + "AM Wintry", + "Mix/Wind" + ], + "6714": [ + "AM Wintry", + "Mix/Wind" + ], + "6800": [ + "Snow", + "Showers" + ], + "6803": [ + "AM Snow", + "Showers" + ], + "6810": [ + "Snow", + "Showers" + ], + "6813": [ + "AM Snow", + "Showers" + ], + "6900": [ + "AM", + "Snow" + ], + "6901": [ + "AM Light", + "Snow" + ], + "6903": [ + "AM", + "Snow" + ], + "6904": [ + "AM Light", + "Snow" + ], + "6910": [ + "AM Snow", + "Wind" + ], + "6911": [ + "AM Light", + "Snow/Wind" + ], + "6913": [ + "AM Snow", + "Wind" + ], + "6914": [ + "AM Snow", + "Wind" + ], + "7000": [ + "PM Drizzle", + "" + ], + "7003": [ + "PM", + "Drizzle" + ], + "7010": [ + "PM Drizzle", + "Wind" + ], + "7013": [ + "PM Drizzle", + "Wind" + ], + "7100": [ + "PM Showers", + "" + ], + "7103": [ + "PM", + "Showers" + ], + "7110": [ + "PM", + "Showers" + ], + "7113": [ + "PM", + "Showers" + ], + "7140": [ + "PM", + "T'Showers" + ], + "7143": [ + "PM", + "T'Showers" + ], + "7170": [ + "PM Showers", + "Wind" + ], + "7173": [ + "PM", + "T'Showers" + ], + "7200": [ + "PM", + "T'Storms" + ], + "7203": [ + "PM", + "T'Storms" + ], + "7210": [ + "PM", + "T'Storms" + ], + "7213": [ + "PM", + "T'Storms" + ], + "7300": [ + "PM", + "Rain" + ], + "7301": [ + "PM", + "Light Rain" + ], + "7303": [ + "PM", + "Rain" + ], + "7304": [ + "PM", + "Light Rain" + ], + "7310": [ + "PM Rain", + "Wind" + ], + "7311": [ + "PM Rain", + "Wind" + ], + "7313": [ + "PM Rain", + "Wind" + ], + "7314": [ + "PM Rain", + "Wind" + ], + "7400": [ + "PM Rain", + "Snow" + ], + "7401": [ + "PM Rain", + "Snow" + ], + "7403": [ + "PM", + "Rain/Snow" + ], + "7404": [ + "PM", + "Rain/Snow" + ], + "7410": [ + "PM Rain", + "Snow/Wind" + ], + "7411": [ + "PM Rain", + "Snow/Wind" + ], + "7413": [ + "PM", + "Rain/Snow" + ], + "7414": [ + "PM", + "Rain/Snow" + ], + "7500": [ + "PM Rain", + "Ice" + ], + "7501": [ + "Light Rain", + "PM Ice" + ], + "7503": [ + "PM", + "Rain/Ice" + ], + "7504": [ + "PM Light", + "Rain/Ice" + ], + "7510": [ + "PM Rain", + "Ice/Wind" + ], + "7511": [ + "Light Rain", + "Ice/Wind" + ], + "7513": [ + "PM Rain", + "Ice/Wind" + ], + "7514": [ + "PM Rain", + "Ice/Wind" + ], + "7600": [ + "PM", + "Ice" + ], + "7603": [ + "PM", + "Ice" + ], + "7610": [ + "PM", + "Ice/Wind" + ], + "7613": [ + "PM", + "Ice/Wind" + ], + "7700": [ + "PM", + "Wintry Mix" + ], + "7701": [ + "PM Light", + "Wintry Mix" + ], + "7703": [ + "PM", + "Wintry Mix" + ], + "7704": [ + "PM Light", + "Wintry Mix" + ], + "7710": [ + "PM Wintry", + "Mix/Wind" + ], + "7711": [ + "PM Wintry", + "Mix/Wind" + ], + "7713": [ + "PM Wintry", + "Mix/Wind" + ], + "7714": [ + "PM Wintry", + "Mix/Wind" + ], + "7800": [ + "PM", + "Snow" + ], + "7803": [ + "PM Snow", + "Showers" + ], + "7810": [ + "PM Snow", + "Wind" + ], + "7813": [ + "PM Snow", + "Wind" + ], + "7900": [ + "PM", + "Snow" + ], + "7901": [ + "PM Light", + "Snow" + ], + "7903": [ + "PM", + "Snow" + ], + "7904": [ + "PM Light", + "Snow" + ], + "7910": [ + "PM Snow", + "Wind" + ], + "7911": [ + "PM Light", + "Snow/Wind" + ], + "7913": [ + "PM Snow", + "Wind" + ], + "7914": [ + "PM Light", + "Snow/Wind" + ], + "8000": [ + "Rain/Snow", + "" + ], + "8010": [ + "Rain", + "Snow/Wind" + ], + "8100": [ + "Rain/Ice", + "" + ], + "8110": [ + "Rain", + "Ice/Wind" + ], + "8200": [ + "Snow", + "Rain" + ], + "8210": [ + "Snow", + "Rain/Wind" + ], + "8300": [ + "Snow/Ice", + "Rain" + ], + "8310": [ + "Snow/Ice", + "Rain/Wind" + ], + "8400": [ + "Snow", + "Ice" + ], + "8410": [ + "Snow", + "Ice/Wind" + ], + "8500": [ + "Ice", + "Rain" + ], + "8510": [ + "Ice", + "Rain/Wind" + ], + "8600": [ + "Ice", + "Snow" + ], + "8610": [ + "Ice", + "Snow/Wind" + ], + "8700": [ + "Wintry Mix", + "Snow" + ], + "8710": [ + "Mix", + "Snow/Wind" + ], + "8800": [ + "Snow", + "Wintry Mix" + ], + "8810": [ + "Snow", + "Mix/Wind" + ], + "8900": [ + "Wintry Mix", + "Rain" + ], + "8910": [ + "Mix", + "Rain/Wind" + ], + "9000": [ + "AM", + "Clouds" + ], + "9003": [ + "AM Clouds", + "PM Sun" + ], + "9010": [ + "P Cloudy", + "Wind" + ], + "9013": [ + "AM Clouds", + "Wind" + ], + "9100": [ + "AM", + "Fog" + ], + "9103": [ + "AM Fog", + "PM Sun" + ], + "9110": [ + "AM Fog", + "Wind" + ], + "9113": [ + "AM Fog", + "Wind" + ], + "9200": [ + "AM Fog", + "PM Clouds" + ], + "9203": [ + "AM Fog", + "PM Clouds" + ], + "9210": [ + "AM Fog", + "Wind" + ], + "9213": [ + "AM Fog", + "Wind" + ], + "9300": [ + "PM", + "Fog" + ], + "9303": [ + "PM", + "Fog" + ], + "9310": [ + "PM", + "Fog/Wind" + ], + "9313": [ + "PM", + "Fog/Wind" + ], + "9500": [ + "Rain", + "Wintry Mix" + ], + "9510": [ + "Rain", + "Mix/Wind" + ] +} \ No newline at end of file diff --git a/src/main/resources/json/ObsMapping.json b/src/main/resources/json/ObsMapping.json new file mode 100644 index 0000000..0a1f954 --- /dev/null +++ b/src/main/resources/json/ObsMapping.json @@ -0,0 +1,378 @@ +{ + "400": "T'Storm", + "401": "Lgt Rn/Thn", + "402": "Hvy T'stm", + "422": "Tornado", + "429": "Funnel Cld", + "470": "T'stm/Wind", + "471": "Lgt Rn/Thn", + "472": "Hvy T'stm", + "480": "T'Strm/Fog", + "481": "Lgt Rn/Thn", + "482": "Hvy T'stm", + "490": "T'stm/Wind", + "491": "Lgt Rn/Thn", + "492": "Hvy T'stm", + "500": "Rain/Snow", + "570": "Rn/Snw/Wnd", + "580": "Rn/Snw/Fog", + "590": "Rn/Snw/Wnd", + "600": "Rain/Sleet", + "610": "Slt/Frz Rn", + "640": "Slt/Frz Rn", + "650": "Rn/Slt/Wnd", + "660": "Slt/Frz Rn", + "670": "Rn/Slt/Fog", + "680": "Slt/Frz Rn", + "690": "Rn/Slt/Wnd", + "700": "Snow/Sleet", + "701": "Lt Snw/Slt", + "705": "Sn/Slt/Wnd", + "706": "Lt Snw/Slt", + "710": "Snw/Frz Rn", + "711": "Lgt Snow", + "715": "Snw/Frz Rn", + "716": "Lgt Snow", + "720": "Wintry Mix", + "725": "Wnt Mx/Wnd", + "730": "Thunder", + "735": "T'Storm", + "750": "Snow/Sleet", + "751": "Lt Snw/Slt", + "755": "Sn/Slt/Wnd", + "756": "Lt Snw/Slt", + "760": "Snw/Frz Rn", + "761": "Lgt Snow", + "765": "Snw/Frz Rn", + "766": "Lgt Snow", + "770": "Wintry Mix", + "775": "Wintry Mix", + "780": "T'Storm", + "785": "T'Storm", + "800": "Frz Rain", + "801": "Lgt Frz Rn", + "802": "Hvy Frz Rn", + "810": "Frz Rain", + "815": "Frz Rn/Wnd", + "820": "Frz Rn/Fog", + "825": "Frz Rn/Fog", + "870": "Frz Rn/Fog", + "871": "Lgt Frz Rn", + "872": "Hvy Frz Rn", + "880": "Frz Rn/Wnd", + "881": "Lgt Frz Rn", + "882": "Hvy Frz Rn", + "890": "Frz Rn/Wnd", + "891": "Lgt Frz Rn", + "892": "Hvy Frz Rn", + "900": "Drizzle", + "901": "Lgt Rain", + "902": "Hvy Rain", + "910": "Rain/Fog", + "980": "Rain/Windy", + "990": "Lgt Rn/Wnd", + "991": "Lgt Rn/Wnd", + "992": "Hvy Rn/Wnd", + "1000": "Frz Rain", + "1001": "Lgt Frz Rn", + "1002": "Hvy Frz Rn", + "1010": "Frz Rain", + "1040": "Frz Rain", + "1050": "Frz Rain", + "1060": "Frz Rain", + "1070": "Frz Rain", + "1071": "Lgt Frz Rn", + "1072": "Hvy Frz Rn", + "1080": "Frz Rain", + "1081": "Lgt Frz Rn", + "1082": "Hvy Frz Rn", + "1090": "Frz Rain", + "1091": "Lgt Frz Rn", + "1092": "Hvy Frz Rn", + "1100": "Shower", + "1101": "Lgt Shower", + "1102": "Hvy Shower", + "1170": "Shower/Wnd", + "1171": "Lgt Shower", + "1172": "Hvy Shower", + "1180": "Shower/Fog", + "1181": "Lgt Shower", + "1182": "Hvy Shower", + "1190": "Shower/Wnd", + "1191": "Lgt Shower", + "1192": "Hvy Shower", + "1200": "Rain", + "1201": "Lgt Rain", + "1202": "Hvy Rain", + "1210": "Frz Rn/Slt", + "1211": "Frz Rn/Slt", + "1212": "Frz Rn/Slt", + "1215": "Frz Rn/Slt", + "1216": "Frz Rn/Slt", + "1217": "Frz Rn/Slt", + "1220": "Frz Rn/Slt", + "1221": "Frz Rn/Slt", + "1222": "Frz Rn/Slt", + "1225": "Frz Rn/Slt", + "1226": "Frz Rn/Slt", + "1227": "Frz Rn/Slt", + "1230": "Frz Rain", + "1231": "Lgt Frz Rn", + "1232": "Hvy Frz Rn", + "1235": "Frz Rain", + "1236": "Lgt Frz Rn", + "1237": "Frz Rain", + "1240": "Frz Rain", + "1241": "Lgt Frz Rn", + "1242": "Hvy Frz Rn", + "1245": "Frz Rain", + "1246": "Lgt Frz Rn", + "1247": "Hvy Frz Rn", + "1270": "Rn/Wnd/Fog", + "1271": "Rn/Wnd/Fog", + "1272": "Hvy Rn/Wnd", + "1280": "Rain/Fog", + "1281": "Lgt Rn/Fog", + "1282": "Hvy Rn/Fog", + "1290": "Rain/Windy", + "1291": "Lgt Rn/Wnd", + "1292": "Hvy Rn/Wnd", + "1310": "Flurries", + "1311": "Flurries", + "1312": "Snow Shwrs", + "1370": "Flurries", + "1371": "Flurries", + "1372": "Snow Shwrs", + "1380": "Flurries", + "1381": "Flurries", + "1382": "Snow Shwrs", + "1390": "Flurries", + "1391": "Flurries", + "1392": "Snow Shwrs", + "1400": "Snow Shwr", + "1401": "Lt Sn Shwr", + "1402": "Hvy Sn Shw", + "1470": "Snow Shwr", + "1471": "Lt Sn Shwr", + "1472": "Hvy Sn Shw", + "1480": "Snow Shwr", + "1481": "Lt Sn Shwr", + "1482": "Hvy Sn Shw", + "1490": "Snow Shwr", + "1491": "Lt Sn Shwr", + "1492": "Hvy Sn Shw", + "1500": "Blw Snow", + "1501": "Drift Snow", + "1509": "Blw Snow", + "1570": "Blw Snow", + "1571": "Drift Snow", + "1579": "Blw Snow", + "1580": "Blw Snow", + "1581": "Drift Snow", + "1589": "Blw Snow", + "1590": "Blw Snow", + "1591": "Drift Snow", + "1599": "Blw Snow", + "1600": "Snow", + "1601": "Lgt Snow", + "1602": "Heavy Snow", + "1630": "T'Snow", + "1631": "T'Snow", + "1632": "T'Snow", + "1640": "T'Snow", + "1641": "Lgt T'Snow", + "1642": "Hvy T'Snow", + "1650": "T'Snow", + "1651": "Lgt T'Snow", + "1652": "Hvy T'Snow", + "1660": "T'Snow", + "1661": "T'Snow", + "1662": "T'Snow", + "1670": "Snow/Fog", + "1671": "Lgt Snow", + "1672": "Hvy Snow", + "1680": "Snow/Windy", + "1681": "Snow/Windy", + "1682": "Hvy Snow", + "1690": "Snow/Windy", + "1691": "Lgt Snow", + "1692": "Hvy Snow", + "1700": "Hail", + "1701": "Small Hail", + "1730": "T'Storm", + "1731": "T'Storm", + "1740": "T'Storm", + "1741": "T'Storm", + "1750": "T'Storm", + "1751": "T'Storm", + "1760": "T'Storm", + "1761": "T'Storm", + "1770": "Hail/Fog", + "1771": "Hail/Fog", + "1780": "T'Storm", + "1781": "T'Storm", + "1790": "Hail/Windy", + "1791": "T'Storm", + "1800": "Sleet", + "1801": "Lgt Sleet", + "1802": "Hvy Sleet", + "1810": "Sleet", + "1811": "T'Snow", + "1816": "T'Snow", + "1821": "T'Snow", + "1826": "T'Snow", + "1830": "T'Storm", + "1831": "T'Storm", + "1832": "T'Storm", + "1840": "T'Storm", + "1841": "T'Storm", + "1842": "T'Storm", + "1850": "Sleet/Fog", + "1851": "Lgt Sleet", + "1852": "Hvy Sleet", + "1860": "Sleet/Fog", + "1861": "Sleet/Wind", + "1870": "Sleet/Wind", + "1880": "T'Storm", + "1881": "T'Storm", + "1882": "T'Storm", + "1885": "T'Storm", + "1886": "T'Storm", + "1887": "T'Storm", + "1890": "Sleet/Wind", + "1891": "Lgt Sleet", + "1892": "Hvy Sleet", + "1895": "T'Storm", + "1896": "Lgt Sleet", + "1897": "Hvy Sleet", + "1900": "Dust", + "1901": "Blw Dust", + "1902": "Blw Dust", + "1910": "Sand", + "1911": "Drift Sand", + "1912": "Blw Sand", + "1919": "Blw Sand", + "1920": "Sandstorm", + "1922": "Hvy S'Strm", + "1929": "Sandstorm", + "1930": "Volc Ash", + "1931": "Duststorm", + "1932": "Hvy D'Strm", + "1939": "Duststorm", + "1960": "Ash/Windy", + "1961": "Duststorm", + "1962": "Hvy D'Strm", + "1969": "Duststorm", + "1970": "Sandstorm", + "1972": "Hvy S'Strm", + "1979": "Duststorm", + "1980": "Sand/Windy", + "1981": "Blw Sand", + "1982": "Blw Sand", + "1989": "Blw Sand", + "1990": "Dust/Windy", + "1991": "Blw Dust", + "1992": "Blw Dust", + "2000": "Fog", + "2001": "Patchy Fog", + "2002": "Mist", + "2021": "Fog", + "2022": "Patchy Fog", + "2081": "Fog", + "2082": "Fog", + "2090": "Fog/Windy", + "2091": "Fog", + "2092": "Mist/Windy", + "2100": "Haze", + "2190": "Haze/Windy", + "2200": "Smoke", + "2290": "Smoke", + "2410": "Blw Spray", + "2420": "Sand/Dust", + "2429": "Duststorm", + "2430": "Windy", + "2450": "Windy/Fog", + "2460": "Windy/Fog", + "2470": "Windy", + "2480": "Sand/Dust", + "2489": "Sand/Dust", + "2490": "Blw Spray", + "2510": "Ice", + "2570": "Ice/Windy", + "2580": "Ice/Fog", + "2590": "Ice/Windy", + "2600": "Cloudy", + "2680": "Showers", + "2681": "Showers", + "2685": "Showers", + "2686": "Showers", + "2690": "Cldy/Wnd", + "2700": "M Cloudy", + "2780": "Showers", + "2781": "Showers", + "2785": "Showers", + "2786": "Showers", + "2790": "Windy", + "2800": "M Cloudy", + "2880": "Showers", + "2881": "Showers", + "2885": "Showers", + "2886": "Showers", + "2890": "Windy", + "2900": "P Cloudy", + "2980": "Showers", + "2981": "Showers", + "2985": "Showers", + "2986": "Showers", + "2990": "Windy", + "3000": "P Cloudy", + "3080": "Showers", + "3081": "Showers", + "3085": "Showers", + "3086": "Showers", + "3090": "Windy", + "3100": "Clear", + "3180": "Showers", + "3181": "Showers", + "3185": "Showers", + "3186": "Showers", + "3190": "Clr/Windy", + "3200": "Sunny", + "3280": "Showers", + "3281": "Showers", + "3285": "Showers", + "3286": "Showers", + "3290": "Sun/Windy", + "3300": "Clear", + "3380": "Showers", + "3381": "Showers", + "3385": "Showers", + "3386": "Showers", + "3390": "Clr/Windy", + "3400": "Sunny", + "3480": "Showers", + "3481": "Showers", + "3485": "Showers", + "3486": "Showers", + "3490": "Sun/Windy", + "3540": "Thunder", + "3549": "Thunder", + "3570": "Thunder", + "3579": "Thunder", + "3580": "Thunder", + "3589": "Thunder", + "3590": "Thunder", + "3599": "Thunder", + "3840": "Thunder", + "3849": "Thunder", + "3870": "Thunder", + "3879": "Thunder", + "3880": "Thunder", + "3889": "Thunder", + "3890": "Thunder", + "3899": "Thunder", + "4400": "N/A", + "4470": "Fog/Windy", + "4480": "???", + "4490": "Fog" +} \ No newline at end of file diff --git a/src/main/resources/json/SlidesManager.json b/src/main/resources/json/SlidesManager.json new file mode 100644 index 0000000..c663d0d --- /dev/null +++ b/src/main/resources/json/SlidesManager.json @@ -0,0 +1,129 @@ +{ + "A": [ + {"segment":"currentConditions", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"hourlyObservations", "duration": 600.0} + ], + "B": [ + {"segment":"hourlyObservations", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0}, + {"segment":"extendedForecast", "duration": 1200.0}, + {"segment":"regionalConditions", "duration": 600.0} + ], + "C": [ + {"segment":"regionalConditions", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"regionalForecast", "duration": 600.0} + ], + "D": [ + {"segment":"hourlyObservations", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"regionalConditions", "duration": 600.0} + ], + "E": [ + {"segment":"localForecast", "duration": 600.0}, + {"segment":"extendedForecast", "duration": 1200.0}, + {"segment":"hourlyObservations", "duration": 600.0} + ], + "F": [ + {"segment":"currentConditions", "duration": 600.0}, + {"segment":"regionalConditions", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0} + ], + "G": [ + {"segment":"localForecast", "duration": 600.0} + ], + "H": [ + {"segment":"localForecast", "duration": 600.0}, + {"segment":"regionalForecast", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0}, + {"segment":"regionalConditions", "duration": 600.0} + ], + "I": [ + {"segment":"currentConditions", "duration": 600.0}, + {"segment":"hourlyObservations", "duration": 600.0}, + {"segment":"regionalConditions", "duration": 600.0} + ], + "J": [ + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"hourlyObservations", "duration": 720.0}, + {"segment":"regionalConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"almanac", "duration": 720.0}, + {"segment":"regionalForecast", "duration": 720.0}, + {"segment":"travelForecast", "duration": 2880.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"outlook", "duration": 720.0} + ], + "K": [ + {"segment":"currentConditions", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0}, + {"segment":"regionalForecast", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"extendedForecast", "duration": 1200.0}, + {"segment":"hourlyObservations", "duration": 600.0} + ], + "L": [ + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"hourlyObservations", "duration": 720.0}, + {"segment":"regionalConditions", "duration": 720.0}, + {"segment":"regionalForecast", "duration": 720.0}, + {"segment":"almanac", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"extendedForecast", "duration": 1440.0} + ], + "M": [ + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"travelForecast", "duration": 2880.0} + ], + "N": [ + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"hourlyObservations", "duration": 720.0}, + {"segment":"regionalConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"almanac", "duration": 720.0}, + {"segment":"regionalForecast", "duration": 720.0}, + {"segment":"travelForecast", "duration": 2880.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"outlook", "duration": 720.0}, + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"travelForecast", "duration": 2880.0} + ], + "O": [ + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"hourlyObservations", "duration": 720.0}, + {"segment":"regionalConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"almanac", "duration": 720.0}, + {"segment":"regionalForecast", "duration": 720.0}, + {"segment":"travelForecast", "duration": 2880.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"outlook", "duration": 720.0}, + {"segment":"currentConditions", "duration": 720.0}, + {"segment":"hourlyObservations", "duration": 720.0}, + {"segment":"regionalConditions", "duration": 720.0}, + {"segment":"localForecast", "duration": 720.0}, + {"segment":"almanac", "duration": 720.0}, + {"segment":"regionalForecast", "duration": 720.0}, + {"segment":"travelForecast", "duration": 2880.0}, + {"segment":"extendedForecast", "duration": 1440.0}, + {"segment":"outlook", "duration": 720.0} + ], + "P": [ + {"segment":"localForecast", "duration": 600.0}, + {"segment":"extendedForecast", "duration": 1200.0}, + {"segment":"currentConditions", "duration": 600.0} + ], + "Q": [ + {"segment":"currentConditions", "duration": 600.0}, + {"segment":"almanac", "duration": 600.0}, + {"segment":"localForecast", "duration": 600.0}, + {"segment":"regionalConditions", "duration": 600.0} + ] +} \ No newline at end of file diff --git a/src/main/resources/shaders/default.glsl b/src/main/resources/shaders/default.glsl new file mode 100644 index 0000000..ab3f135 --- /dev/null +++ b/src/main/resources/shaders/default.glsl @@ -0,0 +1,42 @@ +#type vertex +#version 400 core + +layout (location=0) in vec3 aPos; +layout (location=1) in vec4 aColor; +layout (location=2) in vec2 aTexCoords; +layout (location=3) in float aTexId; + +uniform mat4 uProjection; +uniform mat4 uView; + +out vec4 fColor; +out vec2 fTexCoords; +out float fTexId; + +void main() { + fColor = aColor; + fTexCoords = aTexCoords; + fTexId = aTexId; + + gl_Position = uProjection * uView * vec4(aPos, 1.0); +} + +#type fragment +#version 400 core + +in vec4 fColor; +in vec2 fTexCoords; +in float fTexId; + +uniform sampler2D uTextures[8]; + +out vec4 color; + +void main() { + if (fTexId > 0) { + int id = int(fTexId); + color = fColor * texture(uTextures[id], fTexCoords); + } else { + color = fColor; + } +} \ No newline at end of file