Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSSound.m File Reference
import "OOJSSound.h"
import "OOJavaScriptEngine.h"
import "OOSound.h"
import "OOMusicController.h"
import "ResourceManager.h"
import "Universe.h"
+ Include dependency graph for OOJSSound.m:

Go to the source code of this file.

Enumerations

enum  { kSound_name }
 

Functions

static OOSoundGetNamedSound (NSString *name)
 
static JSBool SoundGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool SoundStaticLoad (JSContext *context, uintN argc, jsval *vp)
 
static JSBool SoundStaticMusicSoundSource (JSContext *context, uintN argc, jsval *vp)
 
static JSBool SoundStaticPlayMusic (JSContext *context, uintN argc, jsval *vp)
 
static JSBool SoundStaticStopMusic (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSSound (JSContext *context, JSObject *global)
 
OOSoundSoundFromJSValue (JSContext *context, jsval value)
 

Variables

static JSObject * sSoundPrototype
 
static JSClass sSoundClass
 
static JSPropertySpec sSoundProperties []
 
static JSFunctionSpec sSoundMethods []
 
static JSFunctionSpec sSoundStaticMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSound_name 

Definition at line 65 of file OOJSSound.m.

66{
67 // Property IDs
69};
@ kSound_name
Definition OOJSSound.m:68

Function Documentation

◆ GetNamedSound()

static OOSound * GetNamedSound ( NSString * name)
static

Definition at line 157 of file OOJSSound.m.

158{
159 OOSound *sound = nil;
160
161 if ([name hasPrefix:@"["] && [name hasSuffix:@"]"])
162 {
163 sound = [OOSound soundWithCustomSoundKey:name];
164 }
165 else
166 {
167 sound = [ResourceManager ooSoundNamed:name inFolder:@"Sounds"];
168 }
169
170 return sound;
171}
return nil
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:11032
OOSound * ooSoundNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References nil, ResourceManager::ooSoundNamed:inFolder:, and OOSound::soundWithCustomSoundKey:.

Referenced by SoundFromJSValue(), and SoundStaticLoad().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitOOJSSound()

void InitOOJSSound ( JSContext * context,
JSObject * global )

Definition at line 104 of file OOJSSound.m.

105{
108}
static JSObject * sSoundPrototype
Definition OOJSSound.m:33
static JSPropertySpec sSoundProperties[]
Definition OOJSSound.m:72
static JSFunctionSpec sSoundMethods[]
Definition OOJSSound.m:80
static JSFunctionSpec sSoundStaticMethods[]
Definition OOJSSound.m:88
static JSClass sSoundClass
Definition OOJSSound.m:48
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sSoundClass, sSoundMethods, sSoundProperties, sSoundPrototype, and sSoundStaticMethods.

+ Here is the call graph for this function:

◆ SoundFromJSValue()

OOSound * SoundFromJSValue ( JSContext * context,
jsval value )

Definition at line 111 of file OOJSSound.m.

112{
114
116 if ([PLAYER status] != STATUS_START_GAME && JSVAL_IS_STRING(value))
117 {
118 return GetNamedSound(OOStringFromJSValue(context, value));
119 }
120 else
121 {
122 return OOJSNativeObjectOfClassFromJSValue(context, value, [OOSound class]);
123 }
125
127}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
static OOSound * GetNamedSound(NSString *name)
Definition OOJSSound.m:157
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
#define PLAYER

References GetNamedSound(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSNativeObjectOfClassFromJSValue(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), and PLAYER.

+ Here is the call graph for this function:

◆ SoundGetProperty()

static JSBool SoundGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 132 of file OOJSSound.m.

133{
134 if (!JSID_IS_INT(propID)) return YES;
135
136 OOJS_NATIVE_ENTER(context)
137
138 OOSound *sound = nil;
139
140 if (EXPECT_NOT(!JSSoundGetSound(context, this, &sound))) return NO;
141
142 switch (JSID_TO_INT(propID))
143 {
144 case kSound_name:
145 *value = OOJSValueFromNativeObject(context, [sound name]);
146 return YES;
147
148 default:
149 OOJSReportBadPropertySelector(context, this, propID, sSoundProperties);
150 return NO;
151 }
152
154}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)

References EXPECT_NOT, kSound_name, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromNativeObject(), and sSoundProperties.

+ Here is the call graph for this function:

◆ SoundStaticLoad()

static JSBool SoundStaticLoad ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 177 of file OOJSSound.m.

178{
179 OOJS_NATIVE_ENTER(context)
180
181 NSString *name = nil;
182 OOSound *sound = nil;
183
184 if (argc > 0) name = OOStringFromJSValue(context, OOJS_ARGV[0]);
185 if (name == nil)
186 {
187 OOJSReportBadArguments(context, @"Sound", @"load", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
188 return NO;
189 }
190
192 sound = GetNamedSound(name);
194
195 OOJS_RETURN_OBJECT(sound);
196
198}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_RETURN_OBJECT(o)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:111

References GetNamedSound(), MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ SoundStaticMusicSoundSource()

static JSBool SoundStaticMusicSoundSource ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 201 of file OOJSSound.m.

202{
203 OOJS_NATIVE_ENTER(context)
204 OOSoundSource *musicSource = nil;
208 OOJS_RETURN_OBJECT(musicSource);
210}
OOMusicController * sharedController()
OOSoundSource * soundSource()

References nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOMusicController::sharedController, and OOMusicController::soundSource.

+ Here is the call graph for this function:

◆ SoundStaticPlayMusic()

static JSBool SoundStaticPlayMusic ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 214 of file OOJSSound.m.

215{
216 OOJS_NATIVE_ENTER(context)
217
218 NSString *name = nil;
219 JSBool loop = NO;
220 double gain = OO_DEFAULT_SOUNDSOURCE_GAIN;
221
222 if (argc > 0) name = OOStringFromJSValue(context, OOJS_ARGV[0]);
223 if (name == nil)
224 {
225 OOJSReportBadArguments(context, @"Sound", @"playMusic", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
226 return NO;
227 }
228 if (argc > 1)
229 {
230 if (!JS_ValueToBoolean(context, OOJS_ARGV[1], &loop))
231 {
232 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 1, nil, @"boolean");
233 return NO;
234 }
235 }
236
237 if (argc > 2)
238 {
239 if (!OOJSArgumentListGetNumber(context, @"Sound", @"playMusic", 2, OOJS_ARGV + 2, &gain, NULL))
240 {
241 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 2, nil, @"float");
242 return NO;
243 }
244 }
245
249
251
253}
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
#define OOJS_RETURN_VOID
void playMusicNamed:loop:gain:(NSString *name,[loop] BOOL loop,[gain] float gain)

References MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSArgumentListGetNumber(), OOJSReportBadArguments(), OOStringFromJSValue(), OOMusicController::playMusicNamed:loop:gain:, and OOMusicController::sharedController.

+ Here is the call graph for this function:

◆ SoundStaticStopMusic()

static JSBool SoundStaticStopMusic ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 257 of file OOJSSound.m.

258{
259 OOJS_NATIVE_ENTER(context)
260
261 NSString *name = nil;
262
263 if (argc > 0)
264 {
265 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
266 if (EXPECT_NOT(name == nil))
267 {
268 OOJSReportBadArguments(context, @"Sound", @"stopMusic", argc, OOJS_ARGV, nil, @"string or no argument");
269 return NO;
270 }
271 }
272
275 if (name == nil || [name isEqualToString:[controller playingMusic]])
276 {
278 }
280
282
284}

Variable Documentation

◆ sSoundClass

JSClass sSoundClass
static
Initial value:
=
{
"Sound",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSSound.m:132
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 48 of file OOJSSound.m.

49{
50 "Sound",
51 JSCLASS_HAS_PRIVATE,
52
53 JS_PropertyStub, // addProperty
54 JS_PropertyStub, // delProperty
55 SoundGetProperty, // getProperty
56 JS_StrictPropertyStub, // setProperty
57 JS_EnumerateStub, // enumerate
58 JS_ResolveStub, // resolve
59 JS_ConvertStub, // convert
60 OOJSObjectWrapperFinalize, // finalize
61 JSCLASS_NO_OPTIONAL_MEMBERS
62};

Referenced by InitOOJSSound().

◆ sSoundMethods

JSFunctionSpec sSoundMethods[]
static
Initial value:
=
{
{ "toString", OOJSObjectWrapperToString, 0, },
{ 0 }
}
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)

Definition at line 80 of file OOJSSound.m.

81{
82 // JS name Function min args
83 { "toString", OOJSObjectWrapperToString, 0, },
84 { 0 }
85};

Referenced by InitOOJSSound().

◆ sSoundProperties

JSPropertySpec sSoundProperties[]
static
Initial value:
=
{
{ 0 }
}
#define OOJS_PROP_READONLY_CB

Definition at line 72 of file OOJSSound.m.

73{
74 // JS name ID flags
76 { 0 }
77};

Referenced by InitOOJSSound(), and SoundGetProperty().

◆ sSoundPrototype

JSObject* sSoundPrototype
static

Definition at line 33 of file OOJSSound.m.

Referenced by InitOOJSSound().

◆ sSoundStaticMethods

JSFunctionSpec sSoundStaticMethods[]
static
Initial value:
=
{
{ "load", SoundStaticLoad, 1, },
{ "musicSoundSource", SoundStaticMusicSoundSource,0, },
{ "playMusic", SoundStaticPlayMusic, 1, },
{ "stopMusic", SoundStaticStopMusic, 0, },
{ 0 }
}
static JSBool SoundStaticStopMusic(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:257
static JSBool SoundStaticPlayMusic(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:214
static JSBool SoundStaticLoad(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:177
static JSBool SoundStaticMusicSoundSource(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:201

Definition at line 88 of file OOJSSound.m.

89{
90 // JS name Function min args
91 { "load", SoundStaticLoad, 1, },
92 { "musicSoundSource", SoundStaticMusicSoundSource,0, },
93 { "playMusic", SoundStaticPlayMusic, 1, },
94 { "stopMusic", SoundStaticStopMusic, 0, },
95 { 0 }
96};

Referenced by InitOOJSSound().