Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSClock.m File Reference
+ Include dependency graph for OOJSClock.m:

Go to the source code of this file.

Enumerations

enum  {
  kClock_absoluteSeconds , kClock_seconds , kClock_minutes , kClock_hours ,
  kClock_days , kClock_secondsComponent , kClock_minutesComponent , kClock_hoursComponent ,
  kClock_daysComponent , kClock_clockString , kClock_isAdjusting , kClock_adjustedSeconds ,
  kClock_legacy_scriptTimer
}
 

Functions

static JSBool ClockGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool JSClockToString (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ClockClockStringForTime (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ClockAddSeconds (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSClock (JSContext *context, JSObject *global)
 

Variables

static JSClass sClockClass
 
static JSPropertySpec sClockProperties []
 
static JSFunctionSpec sClockMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kClock_absoluteSeconds 
kClock_seconds 
kClock_minutes 
kClock_hours 
kClock_days 
kClock_secondsComponent 
kClock_minutesComponent 
kClock_hoursComponent 
kClock_daysComponent 
kClock_clockString 
kClock_isAdjusting 
kClock_adjustedSeconds 
kClock_legacy_scriptTimer 

Definition at line 60 of file OOJSClock.m.

61{
62 // Property IDs
63 kClock_absoluteSeconds, // game real time clock, double, read-only
64 kClock_seconds, // game clock time, double, read-only
65 kClock_minutes, // game clock time minutes (rounded down), integer double, read-only
66 kClock_hours, // game clock time hours (rounded down), integer double, read-only
67 kClock_days, // game clock time days (rounded down), int, read-only
68 kClock_secondsComponent, // second component of game clock time, double, read-only
69 kClock_minutesComponent, // minute component of game clock time (rounded down), int, read-only
70 kClock_hoursComponent, // hour component of game clock time (rounded down), int, read-only
71 kClock_daysComponent, // day component of game clock time (rounded down), int, read-only
72 kClock_clockString, // game clock time as display string, string, read-only
73 kClock_isAdjusting, // clock is adjusting, boolean, read-only
74 kClock_adjustedSeconds, // game clock time, including adjustments, double, read-only
75 kClock_legacy_scriptTimer // legacy scriptTimer_number, double, read-only
76};
@ kClock_absoluteSeconds
Definition OOJSClock.m:63
@ kClock_isAdjusting
Definition OOJSClock.m:73
@ kClock_daysComponent
Definition OOJSClock.m:71
@ kClock_adjustedSeconds
Definition OOJSClock.m:74
@ kClock_days
Definition OOJSClock.m:67
@ kClock_seconds
Definition OOJSClock.m:64
@ kClock_clockString
Definition OOJSClock.m:72
@ kClock_hours
Definition OOJSClock.m:66
@ kClock_secondsComponent
Definition OOJSClock.m:68
@ kClock_hoursComponent
Definition OOJSClock.m:70
@ kClock_minutes
Definition OOJSClock.m:65
@ kClock_minutesComponent
Definition OOJSClock.m:69
@ kClock_legacy_scriptTimer
Definition OOJSClock.m:75

Function Documentation

◆ ClockAddSeconds()

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

Definition at line 218 of file OOJSClock.m.

219{
220 OOJS_NATIVE_ENTER(context)
221
222 double time;
223 const double kMaxTime = 30.0 * 24.0 * 3600.0; // 30 days
224
225 if (EXPECT_NOT(argc < 1 || !JS_ValueToNumber(context, OOJS_ARGV[0], &time)))
226 {
227 jsval arg = JSVAL_VOID;
228 if (argc > 0) arg = OOJS_ARGV[0];
229 OOJSReportBadArguments(context, @"Clock", @"addSeconds", 1, &arg, nil, @"number");
230 return NO;
231 }
232
233 if (time > kMaxTime || time < 1.0 || !isfinite(time))
234 {
236 }
237
238 [OOPlayerForScripting() addToAdjustTime:time];
239
240 OOJS_RETURN_BOOL(YES);
241
243}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_BOOL(v)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
return nil

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, and OOJSReportBadArguments().

+ Here is the call graph for this function:

◆ ClockClockStringForTime()

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

Definition at line 197 of file OOJSClock.m.

198{
199 OOJS_NATIVE_ENTER(context)
200
201 double time;
202
203 if (EXPECT_NOT(argc < 1 || !JS_ValueToNumber(context, OOJS_ARGV[0], &time)))
204 {
205 jsval arg = JSVAL_VOID;
206 if (argc > 0) arg = OOJS_ARGV[0];
207 OOJSReportBadArguments(context, @"Clock", @"clockStringForTime", 1, &arg, nil, @"number");
208 return NO;
209 }
210
212
214}
#define OOJS_RETURN_OBJECT(o)
NSString * ClockToString(double clock, BOOL adjusting)

References ClockToString(), EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJSReportBadArguments().

+ Here is the call graph for this function:

◆ ClockGetProperty()

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

Definition at line 116 of file OOJSClock.m.

117{
118 if (!JSID_IS_INT(propID)) return YES;
119
120 OOJS_NATIVE_ENTER(context)
121
123 double clockTime;
124
125 clockTime = [player clockTime];
126
127 switch (JSID_TO_INT(propID))
128 {
130 return JS_NewNumberValue(context, [UNIVERSE getTime], value);
131
132 case kClock_seconds:
133 return JS_NewNumberValue(context, clockTime, value);
134
135 case kClock_minutes:
136 return JS_NewNumberValue(context, floor(clockTime / 60.0), value);
137
138 case kClock_hours:
139 return JS_NewNumberValue(context, floor(clockTime /3600.0), value);
140 return YES;
141
143 *value = INT_TO_JSVAL(fmod(clockTime, 60.0));
144 return YES;
145
147 *value = INT_TO_JSVAL(fmod(floor(clockTime / 60.0), 60.0));
148 return YES;
149
151 *value = INT_TO_JSVAL(fmod(floor(clockTime / 3600.0), 24.0));
152 return YES;
153
154 case kClock_days:
156 *value = INT_TO_JSVAL(floor(clockTime / 86400.0));
157 return YES;
158
160 *value = OOJSValueFromNativeObject(context, [player dial_clock]);
161 return YES;
162
164 *value = OOJSValueFromBOOL([player clockAdjusting]);
165 return YES;
166
168 return JS_NewNumberValue(context, [player clockTimeAdjusted], value);
169
171 OOStandardsDeprecated(@"The legacy_scriptTimer property is deprecated");
172 return JS_NewNumberValue(context, [player scriptTimer], value);
173
174 default:
175 OOJSReportBadPropertySelector(context, this, propID, sClockProperties);
176 return NO;
177 }
178
180}
void OOStandardsDeprecated(NSString *message)
static JSPropertySpec sClockProperties[]
Definition OOJSClock.m:79
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define UNIVERSE
Definition Universe.h:833

References PlayerEntity::clockTime, kClock_absoluteSeconds, kClock_adjustedSeconds, kClock_clockString, kClock_days, kClock_daysComponent, kClock_hours, kClock_hoursComponent, kClock_isAdjusting, kClock_legacy_scriptTimer, kClock_minutes, kClock_minutesComponent, kClock_seconds, kClock_secondsComponent, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), OOPlayerForScripting(), OOStandardsDeprecated(), sClockProperties, and UNIVERSE.

+ Here is the call graph for this function:

◆ InitOOJSClock()

void InitOOJSClock ( JSContext * context,
JSObject * global )

Definition at line 109 of file OOJSClock.m.

110{
111 JSObject *clockPrototype = JS_InitClass(context, global, NULL, &sClockClass, OOJSUnconstructableConstruct, 0, sClockProperties, sClockMethods, NULL, NULL);
112 JS_DefineObject(context, global, "clock", &sClockClass, clockPrototype, OOJS_PROP_READONLY);
113}
static JSClass sClockClass
Definition OOJSClock.m:43
static JSFunctionSpec sClockMethods[]
Definition OOJSClock.m:99
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY

References OOJS_PROP_READONLY, OOJSUnconstructableConstruct(), sClockClass, sClockMethods, and sClockProperties.

+ Here is the call graph for this function:

◆ JSClockToString()

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

Definition at line 186 of file OOJSClock.m.

187{
188 OOJS_NATIVE_ENTER(context)
189
191
193}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOPlayerForScripting().

+ Here is the call graph for this function:

Variable Documentation

◆ sClockClass

JSClass sClockClass
static
Initial value:
=
{
"Clock",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSClock.m:116

Definition at line 43 of file OOJSClock.m.

44{
45 "Clock",
46 JSCLASS_HAS_PRIVATE,
47
48 JS_PropertyStub, // addProperty
49 JS_PropertyStub, // delProperty
50 ClockGetProperty, // getProperty
51 JS_StrictPropertyStub, // setProperty
52 JS_EnumerateStub, // enumerate
53 JS_ResolveStub, // resolve
54 JS_ConvertStub, // convert
55 JS_FinalizeStub, // finalize
56 JSCLASS_NO_OPTIONAL_MEMBERS
57};

Referenced by InitOOJSClock().

◆ sClockMethods

JSFunctionSpec sClockMethods[]
static
Initial value:
=
{
{ "toString", JSClockToString, 0 },
{ "clockStringForTime", ClockClockStringForTime, 1 },
{ "addSeconds", ClockAddSeconds, 1 },
{ 0 }
}
static JSBool ClockClockStringForTime(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:197
static JSBool ClockAddSeconds(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:218
static JSBool JSClockToString(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:186

Definition at line 99 of file OOJSClock.m.

100{
101 // JS name Function min args
102 { "toString", JSClockToString, 0 },
103 { "clockStringForTime", ClockClockStringForTime, 1 },
104 { "addSeconds", ClockAddSeconds, 1 },
105 { 0 }
106};

Referenced by InitOOJSClock().

◆ sClockProperties

JSPropertySpec sClockProperties[]
static
Initial value:

Definition at line 79 of file OOJSClock.m.

80{
81 // JS name ID flags
82 { "absoluteSeconds", kClock_absoluteSeconds, OOJS_PROP_READONLY_CB },
87 { "secondsComponent", kClock_secondsComponent, OOJS_PROP_READONLY_CB },
88 { "minutesComponent", kClock_minutesComponent, OOJS_PROP_READONLY_CB },
89 { "hoursComponent", kClock_hoursComponent, OOJS_PROP_READONLY_CB },
90 { "daysComponent", kClock_daysComponent, OOJS_PROP_READONLY_CB },
91 { "clockString", kClock_clockString, OOJS_PROP_READONLY_CB },
92 { "isAdjusting", kClock_isAdjusting, OOJS_PROP_READONLY_CB },
93 { "adjustedSeconds", kClock_adjustedSeconds, OOJS_PROP_READONLY_CB },
94 { "legacy_scriptTimer", kClock_legacy_scriptTimer, OOJS_PROP_READONLY_CB },
95 { 0 }
96};

Referenced by ClockGetProperty(), and InitOOJSClock().