• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "environment.h"
17 
18 #include <3d/ecs/components/environment_component.h>
19 #include <core/ecs/intf_entity_manager.h>
20 
SCENE_BEGIN_NAMESPACE()21 SCENE_BEGIN_NAMESPACE()
22 
23 CORE_NS::Entity Environment::CreateEntity(const IInternalScene::Ptr& scene)
24 {
25     auto& ecs = scene->GetEcsContext();
26     auto envm = ecs.FindComponent<CORE3D_NS::EnvironmentComponent>();
27     if (!envm) {
28         return CORE_NS::Entity {};
29     }
30     auto ent = ecs.GetNativeEcs()->GetEntityManager().Create();
31     envm->Create(ent);
32     return ent;
33 }
34 
SetEcsObject(const IEcsObject::Ptr & obj)35 bool Environment::SetEcsObject(const IEcsObject::Ptr& obj)
36 {
37     auto ret = Super::SetEcsObject(obj);
38     if (ret) {
39         Name()->SetValue(GetName());
40         Name()->OnChanged()->AddHandler(META_NS::MakeCallback<META_NS::IOnChanged>([&] {
41             if (this->object_) {
42                 this->object_->SetName(Name()->GetValue());
43             }
44         }));
45     }
46     return ret;
47 }
48 
GetName() const49 BASE_NS::string Environment::GetName() const
50 {
51     return this->object_ ? this->object_->GetName() : "";
52 }
53 
54 SCENE_END_NAMESPACE()
55