MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / createFromString

Method createFromString

Source/GameObject.cpp:496–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496GameObject* GameObject::createFromString(std::string_view data)
497{
498 // data = 1,2,3,4,5,6,7 where [key,value,key,value]
499 auto properties = GameToolbox::splitByDelimStringView(data, ',');
500
501 GameObject* obj = nullptr;
502
503 // index 1 is object id
504 // GameToolbox::log("loading: {}", data);
505 int objectID = GameToolbox::stoi(properties[1]);
506
507 if (!GameObject::_pBlocks.contains(objectID))
508 objectID = 1;
509
510 std::string_view frame = GameObject::_pBlocks.at(objectID);
511
512 // actually create the object
513 if (objectID != 1 && std::find(GameObject::_pTriggers.begin(), GameObject::_pTriggers.end(), objectID) !=
514 GameObject::_pTriggers.end())
515 {
516 obj = EffectGameObject::create(frame);
517 // mylock.unlock();
518 if(obj)
519 {
520 obj->_isTrigger = true;
521 }
522 }
523 else
524 {
525 // mylock.lock();
526 obj = GameObject::create(frame, GameObject::getGlowFrame(objectID));
527 // mylock.unlock();
528 }
529
530 if (!obj)
531 {
532 GameToolbox::log("Could not create object from {}", frame);
533 return nullptr;
534 }
535
536 AX_SAFE_RETAIN(obj);
537
538 obj->setStretchEnabled(false);
539 obj->setActive(true);
540 obj->setID(objectID);
541 obj->customSetup();
542
543 auto bgl = BaseGameLayer::getInstance();
544 // TODO: set uniqueID in base layer
545
546 // iterate over every key
547 for (size_t i = 0; i < properties.size() - 1; i += 2)
548 {
549 int key = GameToolbox::stoi(properties[i]);
550 switch (key)
551 {
552 case 2:
553 obj->setPositionX(GameToolbox::stof(properties[i + 1]));

Callers

nothing calls this directly

Calls 15

findFunction · 0.85
createFunction · 0.85
logFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
setActiveMethod · 0.80
setIDMethod · 0.80
sizeMethod · 0.80
setScaleXMethod · 0.80
setScaleYMethod · 0.80
setRotationMethod · 0.80
setDontTransformMethod · 0.80

Tested by

no test coverage detected