Day Night Cycle DX v2.2

This commit is contained in:
Agent X 2024-07-15 10:48:01 -04:00
parent e32c537525
commit 3d24cd7f6d
10 changed files with 54 additions and 44 deletions

6
mods/day-night-cycle/a-constants.lua Normal file → Executable file
View file

@ -1,8 +1,8 @@
-- version
DNC_VERSION = "v2.1"
DNC_VERSION = "v2.2"
-- skybox constants
E_MODEL_SKYBOX = smlua_model_util_get_id("dnc_skybox_geo")
E_MODEL_DNC_SKYBOX = smlua_model_util_get_id("dnc_skybox_geo")
SKYBOX_SCALE = 600
SKYBOX_DAY = 0
@ -19,7 +19,7 @@ BACKGROUND_BELOW_CLOUDS_SUNSET = 15
-- time constants
SECOND = 30 -- how many frames are in 1 second
MINUTE = SECOND * 60 -- how many frames are in 1 minutes
MINUTE = SECOND * 60 -- how many frames are in 1 minute
HOUR_SUNRISE_START = 4
HOUR_SUNRISE_END = 5

1
mods/day-night-cycle/a-utils.lua Normal file → Executable file
View file

@ -113,6 +113,7 @@ function table_clone(table)
return clone
end
--- Checks common conditions that make HUD rendering out of place
function check_common_hud_render_cancels()
local action = gMarioStates[0].action
return obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil or

25
mods/day-night-cycle/b-time.lua Normal file → Executable file
View file

@ -75,7 +75,6 @@ function set_time_scale(scale)
end
--- @param time number
--- @return string
--- Returns the properly formatted time string
function get_time_string(time)
if type(time) ~= "number" then
@ -122,17 +121,34 @@ function time_tick()
end
end
--- @param sequenceId SeqId
--- @param m64Name string
--- Registers a custom sequence as night music
function night_music_register(sequenceId, m64Name)
if type(sequenceId) ~= "number" or math_floor(sequenceId) ~= sequenceId or sequenceId < 0 or sequenceId >= SEQ_COUNT then
error("night_music_register: Parameter 'sequenceId' must be a SeqId")
return
end
if type(m64Name) ~= "string" then
error("night_music_register: Parameter 'm64Name' must be a string")
return
end
local id = SEQ_COUNT + sequenceId
smlua_audio_utils_replace_sequence(id, 20, 127, m64Name)
smlua_audio_utils_replace_sequence(id, 42, 80, m64Name)
sNightSequences[sequenceId] = id
end
function handle_night_music()
--- Returns whether or not night music should be played
function should_play_night_music()
return is_dnc_enabled() and show_day_night_cycle() and playNightMusic and dayNightCycleApi.playNightMusic
end
function update_night_music()
if gNetworkPlayers[0].currActNum == 99 or gMarioStates[0].area == nil then return end
local musicParam = gMarioStates[0].area.musicParam2
if not playNightMusic or not dayNightCycleApi.playNightMusic then
if not should_play_night_music() then
if playingNightMusic then
playingNightMusic = false
fade_volume_scale(SEQ_PLAYER_LEVEL, 127, 1)
@ -168,6 +184,7 @@ function handle_night_music()
end
--- @param obj Object
--- Function to delete an object if it's dark out, meant to be used in behaviors
function delete_at_dark(obj)
if obj == nil then
error("delete_at_dark: Parameter 'obj' must be an Object")

62
mods/day-night-cycle/main.lua Normal file → Executable file
View file

@ -1,7 +1,6 @@
-- name: Day Night Cycle DX
-- incompatible: light day-night-cycle
-- description: Day Night Cycle DX v2.1\nBy \\#ec7731\\Agent X\n\n\\#dcdcdc\\This mod adds a fully featured day & night cycle system with night, sunrise, day and sunset to sm64coopdx. It includes an API and hook system for interfacing with several components of the mod externally. This mod was originally made for sm64ex-coop but has been practically rewritten for sm64coopdx.\n\nDays last 24 minutes and with the /time command, you can get/set the time or change your settings.\n\nThere is also now a new menu in the pause menu for Day Night Cycle DX!\n\nSpecial thanks to \\#00ffff\\AngelicMiracles\\#dcdcdc\\ for the sunset, sunrise and night time skyboxes.\nSpecial thanks to \\#344ee1\\eros71\\#dcdcdc\\ for salvaging\nthe mod files.
-- pausable: true
-- description: Day Night Cycle DX v2.2\nBy \\#ec7731\\Agent X\n\n\\#dcdcdc\\This mod adds a fully featured day & night cycle system with night, sunrise, day and sunset to sm64coopdx. It includes an API and hook system for interfacing with several components of the mod externally. This mod was originally made for sm64ex-coop but has been practically rewritten for sm64coopdx.\n\nDays last 24 minutes and with the /time command, you can get/set the time or change your settings.\n\nThere is also now a new menu in the pause menu for Day Night Cycle DX!\n\nSpecial thanks to \\#00ffff\\AngelicMiracles\\#dcdcdc\\ for the sunset, sunrise and night time skyboxes.\nSpecial thanks to \\#344ee1\\eros71\\#dcdcdc\\ for salvaging\nthe mod files.
--- @class Vec2f
--- @field public x number
@ -71,28 +70,32 @@ function show_day_night_cycle()
or in_vanilla_level(LEVEL_DDD) or in_vanilla_level(LEVEL_THI) or (in_vanilla_level(LEVEL_CASTLE) and gNetworkPlayers[0].currAreaIndex ~= 3) or in_vanilla_level(LEVEL_WDW)
end
local function reset_lighting()
set_lighting_dir(1, 0)
set_lighting_dir(2, 0)
set_lighting_color(0, 255)
set_lighting_color(1, 255)
set_lighting_color(2, 255)
set_vertex_color(0, 255)
set_vertex_color(1, 255)
set_vertex_color(2, 255)
set_fog_color(0, 255)
set_fog_color(1, 255)
set_fog_color(2, 255)
set_fog_intensity(1)
end
local function update()
if not is_dnc_enabled() then
set_lighting_dir(1, 0)
set_lighting_dir(2, 0)
set_lighting_color(0, 255)
set_lighting_color(1, 255)
set_lighting_color(2, 255)
set_vertex_color(0, 255)
set_vertex_color(1, 255)
set_vertex_color(2, 255)
set_fog_color(0, 255)
set_fog_color(1, 255)
set_fog_color(2, 255)
set_fog_intensity(1)
reset_lighting()
return
end
if network_check_singleplayer_pause() then return end
if network_player_connected_count() == 1 and obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil then return end
if network_is_server() then time_tick() end
if not init then handle_night_music() end
if not init then update_night_music() end
-- spawn skyboxes
local skybox = get_skybox()
@ -110,7 +113,7 @@ local function update()
spawn_non_sync_object(
bhvDNCSkybox,
E_MODEL_SKYBOX,
E_MODEL_DNC_SKYBOX,
0, 0, 0,
--- @param o Object
function(o)
@ -124,7 +127,7 @@ local function update()
-- spawn static skybox
spawn_non_sync_object(
bhvDNCSkybox,
E_MODEL_SKYBOX,
E_MODEL_DNC_SKYBOX,
0, 0, 0,
--- @param o Object
function(o)
@ -174,7 +177,7 @@ local function update()
ambientColor = COLOR_AMBIENT_DAY
end
local overrideAmbientColor = dnc_call_hook(DNC_HOOK_SET_AMBIENT_LIGHTING_COLOR, table_clone(ambientColor))
if overrideAmbientColor ~= nil and type(overrideColor) == "table" then ambientColor = overrideColor end
if overrideAmbientColor ~= nil and type(overrideColor) == "table" then ambientColor = overrideAmbientColor end
-- calculate fog color
local fogColor = COLOR_DAY
@ -244,18 +247,7 @@ local function update()
set_fog_color(2, fogColor.b)
set_fog_intensity(intensity)
else
set_lighting_dir(1, 0)
set_lighting_dir(2, 0)
set_lighting_color(0, 255)
set_lighting_color(1, 255)
set_lighting_color(2, 255)
set_vertex_color(0, 255)
set_vertex_color(1, 255)
set_vertex_color(2, 255)
set_fog_color(0, 255)
set_fog_color(1, 255)
set_fog_color(2, 255)
set_fog_intensity(1)
reset_lighting()
end
init = false
@ -271,7 +263,7 @@ local function on_hud_render_behind()
local scale = 0.5
local text = get_time_string(gGlobalSyncTable.time)
local hidden = hud_is_hidden()
local hidden = hud_is_hidden() or (hud_get_value(HUD_DISPLAY_FLAGS) & HUD_DISPLAY_FLAG_LIVES) == 0
local x = if_then_else(hidden, (djui_hud_get_screen_width() * 0.5) - (djui_hud_measure_text(text) * (0.5 * scale)), 24)
local y = if_then_else(hidden, (djui_hud_get_screen_height() - 20), 32)
local overridePos = dnc_call_hook(DNC_HOOK_SET_DISPLAY_TIME_POS, { x = x, y = y })
@ -414,7 +406,6 @@ local function on_sync_command()
gGlobalSyncTable.timeScale = REAL_MINUTE
save_time()
mod_storage_save_number("scale", REAL_MINUTE)
end
local function on_music_command()
@ -510,7 +501,6 @@ local function on_subtract_hour()
save_time()
end
local sReadonlyMetatable = {
__index = function(table, key)
return rawget(table, key)
@ -536,6 +526,8 @@ _G.dayNightCycleApi = {
get_time_string = get_time_string,
delete_at_dark = delete_at_dark,
show_day_night_cycle = show_day_night_cycle,
should_play_night_music = should_play_night_music,
night_music_register = night_music_register,
dnc_hook_event = dnc_hook_event,
constants = {
SECOND = SECOND,
@ -634,7 +626,7 @@ if network_is_server() then
hook_mod_menu_checkbox("Enable Day Night Cycle", gGlobalSyncTable.dncEnabled, on_set_dnc_enabled)
hook_mod_menu_checkbox("24 Hour Time", use24h, on_set_24h_time)
hook_mod_menu_checkbox("Night Time Music", playNightMusic, on_set_night_time_music)
hook_mod_menu_slider("Time Scale: " .. math_tointeger(gGlobalSyncTable.timeScale), gGlobalSyncTable.timeScale, 0, 20, on_set_time_scale)
hook_mod_menu_slider("Time Scale: " .. gGlobalSyncTable.timeScale, gGlobalSyncTable.timeScale, 0, 20, on_set_time_scale)
hook_mod_menu_button("Add 1 In-Game Hour", on_add_hour)
hook_mod_menu_button("Subtract 1 In-Game Hour", on_subtract_hour)
end

4
mods/day-night-cycle/skybox.lua Normal file → Executable file
View file

@ -2,13 +2,13 @@
local set_override_far,obj_mark_for_deletion,vec3f_to_object_pos,get_skybox,clampf = set_override_far,obj_mark_for_deletion,vec3f_to_object_pos,get_skybox,clampf
--- @param o Object
function bhv_skybox_init(o)
function bhv_dnc_skybox_init(o)
o.header.gfx.skipInViewCheck = true
set_override_far(200000)
end
--- @param o Object
function bhv_skybox_loop(o)
function bhv_dnc_skybox_loop(o)
if not is_dnc_enabled() then
obj_mark_for_deletion(o)
return