Skip to content

Commit

Permalink
Finalized locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jan 1, 2025
1 parent 796e7a5 commit e7aea24
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 364 deletions.
6 changes: 6 additions & 0 deletions resources/js/calendar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// TODO: ABSOLUTELY rewrite this
import { evaluate_calendar_start } from "./calendar/calendar_functions.js";

export default class Calendar {

update(incomingChanges) {
Expand All @@ -22,6 +24,10 @@ export default class Calendar {
return structureChanged;
}

evaluate_calendar_start(year, month=false, day=false, debug=false){
return evaluate_calendar_start(this.static_data, year, month, day, debug);
}

set static_data(value) {
window.static_data = value;
}
Expand Down
337 changes: 0 additions & 337 deletions resources/js/calendar/calendar_inputs_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,309 +698,6 @@ export function set_up_edit_inputs() {
});

});
})

$('.add_inputs.locations .add').click(function() {

var name = $('#location_name_input');
var id = location_list.children().length;

var name_value = name.val() == "" ? `Location ${id + 1}` : name.val();

stats = {
"name": name_value,
"seasons": [],

"settings": {
"timezone": {
"hour": 0,
"minute": 0,
},

"season_based_time": true,

"large_noise_frequency": 0.015,
"large_noise_amplitude": 5.0,

"medium_noise_frequency": 0.3,
"medium_noise_amplitude": 2.0,

"small_noise_frequency": 0.8,
"small_noise_amplitude": 3.0
}
};

for (var i = 0; i < window.static_data.seasons.data.length; i++) {

stats.seasons[i] = {
"time": window.static_data.seasons.data[i].time,
"weather": {
"temp_low": 0,
"temp_high": 0,
"precipitation": 0,
"precipitation_intensity": 0
}
}
}

add_location_to_list(location_list, id, stats);

window.static_data.seasons.locations.push(stats);

repopulate_location_select_list();

name.val('');

// location_list.children().last().find('.slider_percentage').slider({
// min: 0,
// max: 100,
// step: 1,
// change: function(event, ui) {
// $(this).parent().parent().find('.slider_input').val($(this).slider('value')).change();
// },
// slide: function(event, ui) {
// $(this).parent().parent().find('.slider_input').val($(this).slider('value'));
// }
// });

// location_list.children().last().find('.slider_percentage').each(function() {
// $(this).slider('option', 'value', parseInt($(this).parent().parent().find('.slider_input').val()));
// });

location_select.find(`option[value="${id}"]`).prop('selected', true).change();

$('.location_middle_btn').toggleClass('hidden', (!window.static_data.seasons.global_settings.enable_weather && !window.static_data.clock.enabled) || window.static_data.seasons.data.length < 3);

});

$(document).on('focus', '.season_selector', function() {
$(this).prop('prev_value', $(this).val());
});

$(document).on('change', '.season_selector', function() {

var prev_value = $(this).prop('prev_value')
var new_value = $(this).val();

$('.season_selector').not($(this)).each(function(i) {
if ($(this).val() == new_value) {
$(this).val(prev_value)
}
});

$(this).prop('prev_value', $(this).val());

});

$('#copy_location_data').click(function() {

var type = location_select.find('option:selected').parent().attr('value');
var location = location_select.val();

if (type === "custom") {

var stats = clone(window.static_data.seasons.locations[location]);

} else {

var location = clone(preset_data.locations[window.static_data.seasons.data.length][location]);
var stats = {
name: location.name
};

if (window.static_data.seasons.data.length == 2) {
var preset_seasons = ['winter', 'summer'];
} else {
var preset_seasons = ['winter', 'spring', 'summer', 'autumn'];
}

var valid_preset_order = window.static_data.seasons.global_settings.preset_order !== undefined && window.static_data.seasons.global_settings.preset_order.length == window.static_data.seasons.data.length;

var preset_order = undefined;

if (!valid_preset_order) {

let season_test = [];
for (var index in window.static_data.seasons.data) {
var season = window.static_data.seasons.data[index];
let preset_index = preset_seasons.indexOf(season.name.toLowerCase());
if (preset_index == -1 && season.name.toLowerCase() == "fall" && window.static_data.seasons.data.length == 4) {
preset_index = 3;
}
if (preset_index > -1) {
season_test.push(preset_index)
}
}

if (season_test.length == window.static_data.seasons.data.length) {
preset_order = season_test;
valid_preset_order = true;
}

} else {

preset_order = window.static_data.seasons.global_settings.preset_order;

}

stats.settings = clone(preset_data.curves);
stats.settings.season_based_time = true;
stats.seasons = [];

for (var i = 0; i < window.static_data.seasons.data.length; i++) {

var index = i;
if (preset_order !== undefined && preset_order.length == window.static_data.seasons.data.length) {
index = preset_order[i];
}
stats.seasons.push(clone(location.seasons[index]));

stats.seasons[i].time = {}
stats.seasons[i].time.sunset = window.static_data.seasons.data[i].time.sunset;
stats.seasons[i].time.sunrise = window.static_data.seasons.data[i].time.sunrise;

if (window.static_data.seasons.global_settings.temp_sys === "metric" || window.static_data.seasons.global_settings.temp_sys === "both_m") {
stats.seasons[i].weather.temp_low = fahrenheit_to_celcius(stats.seasons[i].weather.temp_low);
stats.seasons[i].weather.temp_high = fahrenheit_to_celcius(stats.seasons[i].weather.temp_high);
}

}

}

var id = location_list.children().length;

add_location_to_list(location_list, id, stats);

window.static_data.seasons.locations.push(stats);

// location_list.children().last().find('.slider_percentage').slider({
// min: 0,
// max: 100,
// step: 1,
// change: function(event, ui) {
// $(this).parent().parent().find('.slider_input').val($(this).slider('value')).change();
// },
// slide: function(event, ui) {
// $(this).parent().parent().find('.slider_input').val($(this).slider('value'));
// }
// });

// location_list.children().last().find('.slider_percentage').each(function() {
// $(this).slider('option', 'value', parseInt($(this).parent().parent().find('.slider_input').val()));
// });

repopulate_location_select_list();

location_select.find('optgroup[value="custom"]').children().eq(id).prop('selected', true).change();

$('.location_middle_btn').toggleClass('hidden', (!window.static_data.seasons.global_settings.enable_weather && !window.static_data.clock.enabled) || window.static_data.seasons.data.length < 3);

});

$(document).on('click', '.location_middle_btn', function() {

var container = $(this).closest('.sortable-container');

var current_season = $(this).closest('.location_season');

var season_id = current_season.attr('fc-index') | 0;

var location_id = container.attr('index') | 0;

var prev_id = (season_id - 1) % window.static_data.seasons.data.length
if (prev_id < 0) prev_id += window.static_data.seasons.data.length

var next_id = (season_id + 1) % window.static_data.seasons.data.length;

if (window.static_data.seasons.global_settings.periodic_seasons) {

var season_length = window.static_data.seasons.data[prev_id].duration + window.static_data.seasons.data[prev_id].transition_length + window.static_data.seasons.data[season_id].duration + window.static_data.seasons.data[season_id].transition_length;
var target = window.static_data.seasons.data[prev_id].duration + window.static_data.seasons.data[prev_id].transition_length;
var perc = target / season_length;

} else {

let prev_season = window.static_data.seasons.data[prev_id];
let curr_season = window.static_data.seasons.data[season_id];
let next_season = window.static_data.seasons.data[next_id];

let prev_year = 2;
if (prev_id > season_id) {
prev_year--;
}

let next_year = 2;
if (next_id < season_id) {
next_year++;
}

let prev_day = evaluate_calendar_start(window.static_data, prev_year, prev_season.timespan, prev_season.day).epoch;
let curr_day = evaluate_calendar_start(window.static_data, 2, curr_season.timespan, curr_season.day).epoch - prev_day;
let next_day = evaluate_calendar_start(window.static_data, next_year, next_season.timespan, next_season.day).epoch - prev_day;

var perc = curr_day / next_day;

}

var prev_season = window.static_data.seasons.locations[location_id].seasons[prev_id];
var next_season = window.static_data.seasons.locations[location_id].seasons[next_id];

if (window.static_data.clock.enabled) {

var prev_sunrise = prev_season.time.sunrise.hour + (prev_season.time.sunrise.minute / window.static_data.clock.minutes);
var next_sunrise = next_season.time.sunrise.hour + (next_season.time.sunrise.minute / window.static_data.clock.minutes);

var middle = lerp(prev_sunrise, next_sunrise, perc)

var sunrise_h = Math.floor(middle)
var sunrise_m = Math.floor(fract(middle) * window.static_data.clock.minutes)

current_season.find("input[clocktype='sunrise_hour']").val(sunrise_h)
current_season.find("input[clocktype='sunrise_minute']").val(sunrise_m)

window.static_data.seasons.locations[location_id].seasons[season_id].time.sunrise.hour = sunrise_h;
window.static_data.seasons.locations[location_id].seasons[season_id].time.sunrise.minute = sunrise_m;


var prev_sunset = prev_season.time.sunset.hour + (prev_season.time.sunset.minute / window.static_data.clock.minutes);
var next_sunset = next_season.time.sunset.hour + (next_season.time.sunset.minute / window.static_data.clock.minutes);

var middle = lerp(prev_sunset, next_sunset, perc)

var sunset_h = Math.floor(middle)
var sunset_m = Math.floor(fract(middle) * window.static_data.clock.minutes)

current_season.find("input[clocktype='sunset_hour']").val(sunset_h)
current_season.find("input[clocktype='sunset_minute']").val(sunset_m)

window.static_data.seasons.locations[location_id].seasons[season_id].time.sunset.hour = sunset_h;
window.static_data.seasons.locations[location_id].seasons[season_id].time.sunset.minute = sunset_m;

}

if (window.static_data.seasons.global_settings.enable_weather) {

var temp_low = precisionRound(lerp(prev_season.weather.temp_low, next_season.weather.temp_low, perc), 2);
var temp_high = precisionRound(lerp(prev_season.weather.temp_high, next_season.weather.temp_high, perc), 2);
var precipitation = precisionRound(lerp(prev_season.weather.precipitation, next_season.weather.precipitation, perc), 2);
var precipitation_intensity = precisionRound(lerp(prev_season.weather.precipitation_intensity, next_season.weather.precipitation_intensity, perc), 2);

// current_season.find("input[fc-index='precipitation']").parent().parent().find('.slider_percentage').slider('option', 'value', precipitation * 100);
// current_season.find("input[fc-index='precipitation_intensity']").parent().parent().find('.slider_percentage').slider('option', 'value', precipitation_intensity * 100);

current_season.find("input[fc-index='temp_high']").val(temp_high)
current_season.find("input[fc-index='temp_low']").val(temp_low)

window.static_data.seasons.locations[location_id].seasons[season_id].weather.temp_low = temp_low;
window.static_data.seasons.locations[location_id].seasons[season_id].weather.temp_high = temp_high;
window.static_data.seasons.locations[location_id].seasons[season_id].weather.precipitation = precipitation;
window.static_data.seasons.locations[location_id].seasons[season_id].weather.precipitation_intensity = precipitation_intensity;

}

do_error_check('seasons');

});

$(document).on('click', '.season_middle_btn', function() {
Expand Down Expand Up @@ -1096,40 +793,6 @@ export function set_up_edit_inputs() {

});

$(document).on('change', '.season_based_time', function() {
let checked = $(this).is(':checked');
if (checked) {
$(this).closest('.sortable-container').find('.location_season').each(function(season_index) {
$(this).find('.clock_inputs input').each(function() {
let [type, time] = $(this).attr('clocktype').split('_');
$(this).val(window.static_data.seasons.data[season_index].time[type][time]).change();
}).prop('disabled', true);
});
} else {
$(this).closest('.sortable-container').find('.location_season').each(function(season_index) {
$(this).find('.clock_inputs input').prop('disabled', false).change();
});
}
});

$(document).on('change', '.season_time', function() {

let index = $(this).closest('.sortable-container').attr('index');

let [type, time] = $(this).attr('clocktype').split('_');

let value = $(this).val();

for (let location_index in window.static_data.seasons.locations) {
let location = window.static_data.seasons.locations[location_index];
if (location.settings.season_based_time) {
location.seasons[index].time[type][time] = Number(value);
location_list.children().eq(location_index).find(`input[clocktype="${$(this).attr('clocktype')}"]`).val(Number(value));
}
}

});


$('.add_inputs.eras .add').click(function() {

Expand Down
8 changes: 4 additions & 4 deletions resources/js/calendar/collapsible_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ export default class CollapsibleComponent {
is_valid = true;
collapsible_name = "Not set on the individual component?!?";

load($store) {
this.calendar_settings = $store.calendar.static_data.settings;
load() {
this.calendar_settings = this.$store.calendar.static_data.settings;

for (let [localKey, globalKey] of Object.entries(this.inboundProperties)) {
let incoming = _.get($store.calendar, globalKey);
let incoming = _.get(this.$store.calendar, globalKey);
let current = this[localKey];

if (!_.isEqual(incoming, current)) {
this[localKey] = incoming;
}
}

this.loaded($store.calendar.static_data);
this.loaded(this.$store.calendar.static_data);

if (!this.initialized) {
this.setupWatchers();
Expand Down
Loading

0 comments on commit e7aea24

Please sign in to comment.