-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvideo.lua
More file actions
119 lines (92 loc) · 3.26 KB
/
video.lua
File metadata and controls
119 lines (92 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package.path = './data/lua/?.lua;' .. package.path
require("sgl")
local __mov_title_volume = 1.0
local __fade_out_time_sec = 1.0
local __id_mov_title = SGL_MOV_ID_INVALID
local __id_sprite_title = SGL_SPRITE_ID_INVALID
local __STATE_PLAYING_NONE = 0
local __STATE_PLAYING_TITLE = 1
local __state_playing = __STATE_PLAYING_TITLE
local __confirmation_fade_out = false
local __confirmation_fade_out_timer = 0
local function __play(state)
-- stop current playing video first
if __state_playing == __STATE_PLAYING_TITLE then
sgl_sprite_activate(__id_sprite_title, false)
sgl_mov_stop(__id_mov_title)
end
__state_playing = state
if __state_playing == __STATE_PLAYING_TITLE then
sgl_mov_play(__id_mov_title)
sgl_sprite_activate(__id_sprite_title, true)
end
end
local function __load(table_resources, table_args)
if not (table_args["mov_title_volume"] == nil) then
__mov_title_volume = table_args["mov_title_volume"]
end
if not (table_args["fade_out_time_sec"] == nil) then
__fade_out_time_sec = table_args["fade_out_time_sec"]
end
local res_mov_title = table_resources["mov_title"]
if res_mov_title == nil then
print("Missing mov_title resource entry")
return false
end
local asset_paths = sgl_asset_paths()
res_mov_title = asset_paths["mov"] .. "/" .. res_mov_title
__id_mov_title = sgl_mov_create(res_mov_title)
sgl_mov_loop(__id_mov_title, -1)
sgl_mov_volume(__id_mov_title, __mov_title_volume)
__id_sprite_title = sgl_sprite_create(sgl_mov_texture(__id_mov_title))
sgl_sprite_pos(__id_sprite_title, 0, 0)
sgl_sprite_dim(__id_sprite_title, sgl_ren_screen_width(), sgl_ren_screen_height())
return true
end
local function __unload()
sgl_sprite_destroy(__id_sprite_title)
sgl_mov_stop(__id_mov_title)
sgl_mov_destroy(__id_mov_title)
end
local function __update(prev_delta_sec, input_state)
if __confirmation_fade_out then
__confirmation_fade_out_timer = __confirmation_fade_out_timer + prev_delta_sec
if __confirmation_fade_out_timer > __fade_out_time_sec then
-- fade out finished
__confirmation_fade_out = false
else
local fade_perc = (__fade_out_time_sec - __confirmation_fade_out_timer) / __fade_out_time_sec
-- fade out only possible when playing title
sgl_mov_volume(__id_mov_title, fade_perc)
sgl_sprite_alpha(__id_sprite_title, math.floor(fade_perc * 0xFF))
end
else
-- don't process inputs on transition
if input_state.digital[SCREEN_ATTRACT_DI_DEBUG_0] then
__play(__STATE_PLAYING_TITLE)
end
end
end
local function __on_enable()
__play(__STATE_PLAYING_TITLE)
end
local function __on_disable()
__play(__STATE_PLAYING_NONE)
end
local function __on_confirm()
__confirmation_fade_out = true
return true
end
local function __on_transition()
-- return true to execute the selected game once the transition is finished
return not __confirmation_fade_out
end
return {
f_load = __load,
f_unload = __unload,
f_update = __update,
f_on_enable = __on_enable,
f_on_disable = __on_disable,
f_on_confirm = __on_confirm,
f_on_transition = __on_transition,
}