1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ags/engine/ac/date_time.h"
24 #include "ags/engine/platform/base/ags_platform_driver.h"
25 #include "ags/engine/script/runtime_script_value.h"
26 #include "ags/shared/debugging/out.h"
27 #include "ags/engine/script/script_api.h"
28 #include "ags/engine/script/script_runtime.h"
29 #include "ags/globals.h"
30 
31 namespace AGS3 {
32 
DateTime_Now_Core()33 ScriptDateTime *DateTime_Now_Core() {
34 	ScriptDateTime *sdt = new ScriptDateTime();
35 
36 	_G(platform)->GetSystemTime(sdt);
37 
38 	return sdt;
39 }
40 
DateTime_Now()41 ScriptDateTime *DateTime_Now() {
42 	ScriptDateTime *sdt = DateTime_Now_Core();
43 	ccRegisterManagedObject(sdt, sdt);
44 	return sdt;
45 }
46 
DateTime_GetYear(ScriptDateTime * sdt)47 int DateTime_GetYear(ScriptDateTime *sdt) {
48 	return sdt->year;
49 }
50 
DateTime_GetMonth(ScriptDateTime * sdt)51 int DateTime_GetMonth(ScriptDateTime *sdt) {
52 	return sdt->month;
53 }
54 
DateTime_GetDayOfMonth(ScriptDateTime * sdt)55 int DateTime_GetDayOfMonth(ScriptDateTime *sdt) {
56 	return sdt->day;
57 }
58 
DateTime_GetHour(ScriptDateTime * sdt)59 int DateTime_GetHour(ScriptDateTime *sdt) {
60 	return sdt->hour;
61 }
62 
DateTime_GetMinute(ScriptDateTime * sdt)63 int DateTime_GetMinute(ScriptDateTime *sdt) {
64 	return sdt->minute;
65 }
66 
DateTime_GetSecond(ScriptDateTime * sdt)67 int DateTime_GetSecond(ScriptDateTime *sdt) {
68 	return sdt->second;
69 }
70 
DateTime_GetRawTime(ScriptDateTime * sdt)71 int DateTime_GetRawTime(ScriptDateTime *sdt) {
72 	return sdt->rawUnixTime;
73 }
74 
75 //=============================================================================
76 //
77 // Script API Functions
78 //
79 //=============================================================================
80 
81 // ScriptDateTime* ()
Sc_DateTime_Now(const RuntimeScriptValue * params,int32_t param_count)82 RuntimeScriptValue Sc_DateTime_Now(const RuntimeScriptValue *params, int32_t param_count) {
83 	API_SCALL_OBJAUTO(ScriptDateTime, DateTime_Now);
84 }
85 
86 // int (ScriptDateTime *sdt)
Sc_DateTime_GetYear(void * self,const RuntimeScriptValue * params,int32_t param_count)87 RuntimeScriptValue Sc_DateTime_GetYear(void *self, const RuntimeScriptValue *params, int32_t param_count) {
88 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetYear);
89 }
90 
91 // int (ScriptDateTime *sdt)
Sc_DateTime_GetMonth(void * self,const RuntimeScriptValue * params,int32_t param_count)92 RuntimeScriptValue Sc_DateTime_GetMonth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
93 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetMonth);
94 }
95 
96 // int (ScriptDateTime *sdt)
Sc_DateTime_GetDayOfMonth(void * self,const RuntimeScriptValue * params,int32_t param_count)97 RuntimeScriptValue Sc_DateTime_GetDayOfMonth(void *self, const RuntimeScriptValue *params, int32_t param_count) {
98 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetDayOfMonth);
99 }
100 
101 // int (ScriptDateTime *sdt)
Sc_DateTime_GetHour(void * self,const RuntimeScriptValue * params,int32_t param_count)102 RuntimeScriptValue Sc_DateTime_GetHour(void *self, const RuntimeScriptValue *params, int32_t param_count) {
103 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetHour);
104 }
105 
106 // int (ScriptDateTime *sdt)
Sc_DateTime_GetMinute(void * self,const RuntimeScriptValue * params,int32_t param_count)107 RuntimeScriptValue Sc_DateTime_GetMinute(void *self, const RuntimeScriptValue *params, int32_t param_count) {
108 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetMinute);
109 }
110 
111 // int (ScriptDateTime *sdt)
Sc_DateTime_GetSecond(void * self,const RuntimeScriptValue * params,int32_t param_count)112 RuntimeScriptValue Sc_DateTime_GetSecond(void *self, const RuntimeScriptValue *params, int32_t param_count) {
113 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetSecond);
114 }
115 
116 // int (ScriptDateTime *sdt)
Sc_DateTime_GetRawTime(void * self,const RuntimeScriptValue * params,int32_t param_count)117 RuntimeScriptValue Sc_DateTime_GetRawTime(void *self, const RuntimeScriptValue *params, int32_t param_count) {
118 	API_OBJCALL_INT(ScriptDateTime, DateTime_GetRawTime);
119 }
120 
RegisterDateTimeAPI()121 void RegisterDateTimeAPI() {
122 	ccAddExternalStaticFunction("DateTime::get_Now", Sc_DateTime_Now);
123 	ccAddExternalObjectFunction("DateTime::get_DayOfMonth", Sc_DateTime_GetDayOfMonth);
124 	ccAddExternalObjectFunction("DateTime::get_Hour", Sc_DateTime_GetHour);
125 	ccAddExternalObjectFunction("DateTime::get_Minute", Sc_DateTime_GetMinute);
126 	ccAddExternalObjectFunction("DateTime::get_Month", Sc_DateTime_GetMonth);
127 	ccAddExternalObjectFunction("DateTime::get_RawTime", Sc_DateTime_GetRawTime);
128 	ccAddExternalObjectFunction("DateTime::get_Second", Sc_DateTime_GetSecond);
129 	ccAddExternalObjectFunction("DateTime::get_Year", Sc_DateTime_GetYear);
130 }
131 
132 } // namespace AGS3
133