1 /*
2  Copyright (c) 2013 yvt
3 
4  This file is part of OpenSpades.
5 
6  OpenSpades is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OpenSpades is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OpenSpades.  If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 #include "ScriptManager.h"
22 #include "IToolSkin.h"
23 #include <Core/Debug.h>
24 
25 namespace spades{
26 	namespace client {
ScriptIToolSkin(asIScriptObject * obj)27 		ScriptIToolSkin::ScriptIToolSkin(asIScriptObject *obj):
28 		obj(obj){}
29 
SetSprintState(float v)30 		void ScriptIToolSkin::SetSprintState(float v) {
31 			SPADES_MARK_FUNCTION_DEBUG();
32 			static ScriptFunction func("IToolSkin",
33 									   "void set_SprintState(float)");
34 			ScriptContextHandle ctx = func.Prepare();
35 			int r;
36 			r = ctx->SetObject((void *)obj);
37 			ScriptManager::CheckError(r);
38 			r = ctx->SetArgFloat(0, v);
39 			ScriptManager::CheckError(r);
40 			ctx.ExecuteChecked();
41 		}
42 
SetRaiseState(float v)43 		void ScriptIToolSkin::SetRaiseState(float v){
44 			SPADES_MARK_FUNCTION_DEBUG();
45 			static ScriptFunction func("IToolSkin",
46 									   "void set_RaiseState(float)");
47 			ScriptContextHandle ctx = func.Prepare();
48 			int r;
49 			r = ctx->SetObject((void *)obj);
50 			ScriptManager::CheckError(r);
51 			r = ctx->SetArgFloat(0, v);
52 			ScriptManager::CheckError(r);
53 			ctx.ExecuteChecked();
54 		}
SetMuted(bool v)55 		void ScriptIToolSkin::SetMuted(bool v){
56 			SPADES_MARK_FUNCTION_DEBUG();
57 			static ScriptFunction func("IToolSkin",
58 									   "void set_IsMuted(bool)");
59 			ScriptContextHandle ctx = func.Prepare();
60 			int r;
61 			r = ctx->SetObject((void *)obj);
62 			ScriptManager::CheckError(r);
63 			r = ctx->SetArgByte(0, v?1:0);
64 			ScriptManager::CheckError(r);
65 			ctx.ExecuteChecked();
66 		}
SetTeamColor(Vector3 v)67 		void ScriptIToolSkin::SetTeamColor(Vector3 v){
68 			SPADES_MARK_FUNCTION_DEBUG();
69 			static ScriptFunction func("IToolSkin",
70 									   "void set_TeamColor(Vector3)");
71 			ScriptContextHandle ctx = func.Prepare();
72 			int r;
73 			r = ctx->SetObject((void *)obj);
74 			ScriptManager::CheckError(r);
75 			r = ctx->SetArgObject(0, &v);
76 			ScriptManager::CheckError(r);
77 			ctx.ExecuteChecked();
78 		}
Update(float v)79 		void ScriptIToolSkin::Update(float v) {
80 			SPADES_MARK_FUNCTION_DEBUG();
81 			static ScriptFunction func("IToolSkin",
82 									   "void Update(float)");
83 			ScriptContextHandle ctx = func.Prepare();
84 			int r;
85 			r = ctx->SetObject((void *)obj);
86 			ScriptManager::CheckError(r);
87 			r = ctx->SetArgFloat(0, v);
88 			ScriptManager::CheckError(r);
89 			ctx.ExecuteChecked();
90 		}
91 
AddToScene()92 		void ScriptIToolSkin::AddToScene() {
93 			SPADES_MARK_FUNCTION_DEBUG();
94 			static ScriptFunction func("IToolSkin",
95 									   "void AddToScene()");
96 			ScriptContextHandle ctx = func.Prepare();
97 			int r;
98 			r = ctx->SetObject((void *)obj);
99 			ScriptManager::CheckError(r);
100 			ctx.ExecuteChecked();
101 		}
102 
103 		class IToolSkinRegistrar: public ScriptObjectRegistrar {
104 		public:
IToolSkinRegistrar()105 			IToolSkinRegistrar():
106 			ScriptObjectRegistrar("IToolSkin"){
107 
108 			}
Register(ScriptManager * manager,Phase phase)109 			virtual void Register(ScriptManager *manager, Phase phase) {
110 				asIScriptEngine *eng = manager->GetEngine();
111 				int r;
112 				eng->SetDefaultNamespace("spades");
113 				switch(phase){
114 					case PhaseObjectType:
115 						r = eng->RegisterInterface("IToolSkin");
116 						manager->CheckError(r);
117 
118 
119 						break;
120 					case PhaseObjectMember:
121 						r = eng->RegisterInterfaceMethod("IToolSkin",
122 														 "void set_SprintState(float)");
123 						manager->CheckError(r);
124 						r = eng->RegisterInterfaceMethod("IToolSkin",
125 														 "void set_RaiseState(float)");
126 						manager->CheckError(r);
127 						r = eng->RegisterInterfaceMethod("IToolSkin",
128 														 "void set_TeamColor(Vector3)");
129 						manager->CheckError(r);
130 						r = eng->RegisterInterfaceMethod("IToolSkin",
131 														 "void set_IsMuted(bool)");
132 						manager->CheckError(r);
133 						r = eng->RegisterInterfaceMethod("IToolSkin",
134 														 "void Update(float)");
135 						manager->CheckError(r);
136 						r = eng->RegisterInterfaceMethod("IToolSkin",
137 														 "void AddToScene()");
138 						manager->CheckError(r);
139 
140 						break;
141 					default:
142 
143 						break;
144 				}
145 			}
146 		};
147 
148 		static IToolSkinRegistrar registrar;
149 	}
150 }
151 
152