1212#include " Components/Transform.h"
1313#include " Components/Camera.h"
1414#include " Engine/Engine.h"
15- #include " Components/UI/BasicUIView.h"
16- #include " Scripting/MonoUtils.h"
17- #include < Web\HttpDownload.h>
18- #include " File.h"
19- #include < mono\metadata\appdomain.h>
20-
2115
2216#if USING( ME_SCRIPTING )
2317static std::unordered_map<MonoType*, std::function<bool ( EntityHandle )>> s_EntityHasComponentFuncs;
@@ -38,10 +32,7 @@ static void RegisterComponent()
3832 YIKES ( " Could not find component type {}" );
3933 return ;
4034 }
41- s_EntityHasComponentFuncs[managedType] = []( EntityHandle entity )
42- {
43- return entity->HasComponent <Component>();
44- };
35+ s_EntityHasComponentFuncs[managedType] = []( EntityHandle entity ) { return entity->HasComponent <Component>(); };
4536 }( ), ... );
4637}
4738#endif
@@ -54,19 +45,14 @@ ScriptComponent::ScriptComponent()
5445 // Did you update your bgfx .hpp shaders at all??
5546 mono_add_internal_call ( " Transform::Entity_GetTranslation" , (void *)Transform_GetTranslation );
5647 mono_add_internal_call ( " Transform::Entity_GetTranslation" , (void *)Transform_GetTranslation );
57- mono_add_internal_call ( " Transform::Transform_GetScale" , (void *)Transform_GetScale );
58- mono_add_internal_call ( " Transform::Transform_SetScale" , (void *)Transform_SetScale );
5948 mono_add_internal_call ( " Camera::Camera_GetClearColor" , (void *)Camera_GetClearColor );
6049 mono_add_internal_call ( " Camera::Camera_SetClearColor" , (void *)Camera_SetClearColor );
6150 mono_add_internal_call ( " Input::IsKeyDown" , (void *)Input_IsKeyDown );
6251
6352 mono_add_internal_call ( " Entity::Entity_HasComponent" , (void *)Entity_HasComponent );
64- mono_add_internal_call ( " BasicUIView::BasicUIView_ExecuteJS" , (void *)BasicUIView_ExecuteJS );
65- mono_add_internal_call ( " HTTP::HTTP_DownloadFile" , (void *)HTTP_DownloadFile );
6653 // does this go into the other components?
6754 RegisterComponent<Transform>();
6855 RegisterComponent<Camera>();
69- RegisterComponent<BasicUIView>();
7056#endif
7157}
7258
@@ -90,18 +76,15 @@ void ScriptComponent::Init()
9076 for ( const auto & [name, fieldInstance] : fieldMap )
9177 {
9278 Instance->SetFieldValueInternal ( name, (void *)fieldInstance.Buffer );
79+ ScriptName = foundClass->first ;
80+ Instance->OnCreate ();
9381 }
9482 }
95- ScriptName = foundClass->first ;
96-
97- // Call OnCreate exactly ONCE after initialization:
98- Instance->OnCreate ();
9983 }
10084 }
10185#endif
10286}
10387
104-
10588#if USING( ME_EDITOR )
10689
10790void ScriptComponent::OnEditorInspect ()
@@ -135,7 +118,6 @@ void ScriptComponent::OnEditorInspect()
135118 ImGui::Text ( ScriptName.c_str () );
136119
137120 // Add a inspect settings option passed in
138- // #TODO: questionable??
139121 if ( true )// if ( static_cast<EditorApp*>( GetEngine().GetGame() )->IsGameRunning() )
140122 {
141123 ScriptClass& scriptClass = ScriptEngine::GetEntityClass ( ScriptName );
@@ -310,18 +292,6 @@ void ScriptComponent::Transform_SetTranslation( EntityID id, Vector3* inPos )
310292 handle->GetComponent <Transform>().SetPosition ( *inPos );
311293}
312294
313- void ScriptComponent::Transform_GetScale ( EntityID id, Vector3* outPosition )
314- {
315- EntityHandle handle ( id, ScriptEngine::sScriptData .worldPtr );
316- *outPosition = handle->GetComponent <Transform>().GetScale ();
317- }
318-
319- void ScriptComponent::Transform_SetScale ( EntityID id, Vector3* inPos )
320- {
321- EntityHandle handle ( id, ScriptEngine::sScriptData .worldPtr );
322- handle->GetComponent <Transform>().SetScale ( *inPos );
323- }
324-
325295void ScriptComponent::Camera_GetClearColor ( EntityID id, Vector3* outPosition )
326296{
327297 EntityHandle handle ( id, ScriptEngine::sScriptData .worldPtr );
@@ -334,37 +304,8 @@ void ScriptComponent::Camera_SetClearColor( EntityID id, Vector3* inPos )
334304 handle->GetComponent <Camera>().ClearColor = *inPos;
335305}
336306
337-
338- void ScriptComponent::BasicUIView_ExecuteJS ( EntityID id, MonoString* inString )
339- {
340- EntityHandle handle ( id, ScriptEngine::sScriptData .worldPtr );
341- if ( handle )
342- {
343- handle->GetComponent <BasicUIView>().ExecuteScript ( MonoUtils::MonoStringToUTF8 ( inString ) );
344- }
345- }
346-
347-
348- MonoString* ScriptComponent::HTTP_DownloadFile ( MonoString* inURL, MonoString* inDirectory )
349- {
350- char * str = mono_string_to_utf8 ( inURL );
351- char * inDirectoryMono = mono_string_to_utf8 ( inDirectory );
352- Path outPath = Path ( inDirectoryMono );
353- if ( Web::DownloadFile ( str, outPath ) )
354- {
355- return mono_string_new ( mono_domain_get (), File ( outPath ).Read ().c_str () );
356- }
357- return nullptr ;
358- }
359-
360-
361307bool ScriptComponent::Entity_HasComponent ( EntityID id, MonoReflectionType* inType )
362308{
363- if ( id.IsNull () )
364- {
365- return false ;
366- }
367-
368309 EntityHandle handle ( id, ScriptEngine::sScriptData .worldPtr );
369310
370311 MonoType* managedType = mono_reflection_type_get_type ( inType );
0 commit comments