MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / init

Method init

Source/Platformer/Unit.cpp:117–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 entity, pos, rot) { }
116
117bool Unit::init() {
118 if (!Body::init()) return false;
119 auto defaultFaceRight = _unitDef->get(Def::DefaultFaceRight, true);
120 auto detectDistance = _unitDef->get(Def::DetectDistance, 0.0f);
121 auto attackRange = _unitDef->get(Def::AttackRange, Size::zero);
122 auto tag = _unitDef->get(Def::Tag, Slice::Empty);
123 auto playableStr = _unitDef->get(Def::Playable, Slice::Empty);
124 auto scale = _unitDef->get(Def::Scale, 1.0f);
125 auto actions = _unitDef->get(Def::Actions, s_cast<Array*>(nullptr));
126 _flags.set(Unit::DefaultFaceRight, defaultFaceRight);
127 Unit::setDetectDistance(detectDistance);
128 Unit::setAttackRange(attackRange);
129 Unit::setTag(tag);
130 _groundSensor = Body::getSensorByTag(Unit::GroundSensorTag);
131 Playable* playable = Playable::create(playableStr);
132 if (!playable) {
133 Error("failed to load playable \"{}\" for an new unit.", playableStr);
134 Unit::cleanup();
135 return false;
136 }
137 playable->setScaleX(scale);
138 playable->setScaleY(scale);
139 Unit::setPlayable(playable);
140 Unit::setFaceRight(true);
141 Body::setOwner(this);
142 ARRAY_START_VAL(std::string, action, actions) {
143 Unit::attachAction(action);
144 }
145 ARRAY_END
146 _decisionTreeName = _unitDef->get(Def::DecisionTree, Slice::Empty);
147 _entity->set("unit"_slice, s_cast<Object*>(this));
148 this->scheduleUpdate();
149 return true;
150}
151
152void Unit::onEnter() {
153 Body::onEnter();

Callers

nothing calls this directly

Calls 10

cleanupFunction · 0.85
setOwnerFunction · 0.85
getMethod · 0.65
setMethod · 0.65
initFunction · 0.50
createFunction · 0.50
ErrorEnum · 0.50
setScaleXMethod · 0.45
setScaleYMethod · 0.45
scheduleUpdateMethod · 0.45

Tested by

no test coverage detected