-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvorple-multimedia.h
186 lines (151 loc) · 6.21 KB
/
vorple-multimedia.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#Ifndef VORPLE_MULTIMEDIA;
System_file;
Constant VORPLE_MULTIMEDIA;
Include "vorple.h";
! Displaying images and playing sounds and music.
!===================================
! Images
[ VorpleImageInElement file desc classes id ;
if (desc == 0) { desc = ""; }
if (classes == 0) { classes = ""; }
if (isVorpleSupported()) {
id = UniqueIdentifier();
VorplePlaceDivElement(BuildCommand(id, " vorple-image ", classes), "");
! two vorple escapes -> can't use buildcommand (TODO: fix this?)
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "$('<img>', {src: vorple.file.resourceUrl(vorple.options.resource_paths.images+'";
PrintStringOrArray(VorpleEscape(file));
print "'), alt: '";
PrintStringOrArray(VorpleEscape(desc));
print "'}).appendTo('.";
PrintStringOrArray(id);
print "')";
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
} else {
print (string) desc;
print "^";
}
];
Constant IMAGE_CENTERED = 1;
Constant IMAGE_LEFT_ALIGNED = 2;
Constant IMAGE_RIGHT_ALIGNED = 3;
Constant IMAGE_LEFT_FLOATING = 4;
Constant IMAGE_RIGHT_FLOATING = 5;
[ VorpleImage file desc alignment classes ;
if (desc == 0) { desc = ""; }
if (classes == 0) { classes = ""; }
if (classes == "") {
switch(alignment) {
IMAGE_CENTERED: VorpleImageInElement(file, desc, "centered");
IMAGE_LEFT_ALIGNED: VorpleImageInElement(file, desc, "left-aligned");
IMAGE_RIGHT_ALIGNED: VorpleImageInElement(file, desc, "right-aligned");
IMAGE_LEFT_FLOATING: VorpleImageInElement(file, desc, "left-floating");
IMAGE_RIGHT_FLOATING: VorpleImageInElement(file, desc, "right-floating");
default: VorpleImageInElement(file, desc, classes);
}
} else {
switch(alignment) {
IMAGE_CENTERED: VorpleImageInElement(file, desc, BuildCommand("centered", " ", classes));
IMAGE_LEFT_ALIGNED: VorpleImageInElement(file, desc, BuildCommand("left-aligned", " ", classes));
IMAGE_RIGHT_ALIGNED: VorpleImageInElement(file, desc, BuildCommand("right-aligned", " ", classes));
IMAGE_LEFT_FLOATING: VorpleImageInElement(file, desc, BuildCommand("left-floating", " ", classes));
IMAGE_RIGHT_FLOATING: VorpleImageInElement(file, desc, BuildCommand("right-floating", " ", classes));
default: VorpleImageInElement(file, classes, desc);
}
}
];
[ VorplePreloadImage file ;
VorpleExecuteJavaScriptCommand(BuildCommand("new Image().src=vorple.file.resourceUrl(vorple.options.resource_paths.images+'", VorpleEscape(file), "');"));
];
[ VorplePreloadImages list len i ;
! List must be a table, like page 43 of DM4
len = list-->0;
for (i=1: i<=len: i++) { VorplePreloadImage(list-->i); }
];
!===================================
! Audio
Constant SOUND_LOOP = 1;
[ VorplePlaySoundEffect file loop;
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "vorple.audio.playSound(vorple.options.resource_paths.audio+'";
PrintStringOrArray(VorpleEscape(file));
print "', {looping: ";
if (loop == SOUND_LOOP) { print "true"; } else { print "false"; }
print "})";
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
];
Constant MUSIC_LOOP = 1;
Constant MUSIC_FROM_START = 1;
[ VorplePlayMusic file loop from_start;
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "vorple.audio.playMusic(vorple.options.resource_paths.audio+'";
PrintStringOrArray(VorpleEscape(file));
print "', {looping: ";
if (loop == MUSIC_LOOP) { print "true"; } else { print "false"; }
print ", restart: ";
if (from_start == MUSIC_FROM_START) { print "true"; } else { print "false"; }
print "})";
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
];
[ VorpleStopMusic ;
VorpleExecuteJavaScriptCommand("vorple.audio.stopMusic()");
];
[ VorpleStopSoundEffects ;
VorpleExecuteJavaScriptCommand("$('.vorple-sound-effect').remove()");
];
[ VorpleStopAudio ;
VorpleExecuteJavaScriptCommand("$('.vorple-sound-effect').remove();vorple.audio.stopMusic()");
];
Constant PLAYLIST_LOOP = 1;
Constant PLAYLIST_SHUFFLE = 1;
Constant PLAYLIST_FROM_START = 1;
[ VorpleStartPlaylist playlist loop from_start shuffle len i j tmp;
! Playlist must be a table, like page 43 of DM4
! We write the full command in hugehugestr (cant just write the playlist in it because BuildCommand writes in it)
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "var pl=";
! the array
print "[";
len = playlist-->0;
for (i=0: i<len: i++) {
print "vorple.options.resource_paths.audio+'", (PrintStringOrArray) VorpleEscape((playlist-->(i+1))), "',";
}
print "'']";
! the rest
print ";pl.pop();vorple.audio.setPlaylist(pl, {looping: ";
if (loop == PLAYLIST_LOOP) { print "true"; } else { print "false"; }
print ", restart:";
if (from_start == PLAYLIST_FROM_START) { print "true"; } else { print "false"; }
print ", shuffled:";
if (shuffle == PLAYLIST_SHUFFLE) { print "true"; } else { print "false"; }
print "})";
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
];
[ VorpleClearPlaylist ;
VorpleExecuteJavaScriptCommand("return vorple.audio.clearPlaylist()");
];
[ VorpleIsMusicPlaying ;
VorpleExecuteJavaScriptCommand("return vorple.audio.isMusicPlaying()");
return VorpleWhatBooleanWasReturned();
];
[ VorpleIsASoundEffectPlaying ;
VorpleExecuteJavaScriptCommand("return vorple.audio.isEffectPlaying()");
return VorpleWhatBooleanWasReturned();
];
[ VorpleIsAudioPlaying ;
VorpleExecuteJavaScriptCommand("return vorple.audio.isAudioPlaying()");
return VorpleWhatBooleanWasReturned();
];
[ VorpleIsAudioFilePlaying file ;
VorpleExecuteJavaScriptCommand(BuildCommand("return vorple.audio.isElementPlaying('.vorple-audio[src=@@92''+vorple.options.resource_paths.audio+'", VorpleEscape(file), "@@92']')"));
return VorpleWhatBooleanWasReturned();
];
[ VorpleGetMusicFilePlaying ;
VorpleExecuteJavaScriptCommand("return vorple.audio.currentMusicPlaying()||''");
return VorpleWhatTextWasReturned();
];
#Endif;