Example #1
0
 void Sprite::LoadFromText(const char *text)
 {
     TextParser parser;
     parser.Parse(text);
     TextParser::NODE *node = NULL;
     if ((node = parser.GetNode("FILETYPE")) && node->values[0] == "SPRITE")
     {
         if ((node = parser.GetNode("RESOURCE")))
         {
             _texture = static_cast<Texture*>(LE_ResourceManager.GetResourceWithRegister(node->values[0].GetCharPtr())->data);
         }
         if ((node = parser.GetNode("FRAMES")))
         {
             for (size_t i = 0; i<node->children.count(); i++)
             {
                 TextParser::NODE *child = node->children[i];
                 if (child)
                 {
                     TextParser::NODE *node_rect = child->FindChild("RECT");
                     if (node_rect)
                     {
                         AddFrame(iRect(node_rect->values[0].ToInt(),
                             node_rect->values[1].ToInt(),
                             node_rect->values[2].ToInt(),
                             node_rect->values[3].ToInt()
                         ));
                     }
                 }
             }
         }
     }
 }
Example #2
0
void SceneManager::LoadFromText(const char *text)
{
    TextParser parser;
    parser.Parse(text);
    TextParser::NODE *node = NULL;
    if ((node = parser.GetNode("FILETYPE")) && node->values[0] == "SCENE")
    {
        TextParser::NODE *node_data = parser.GetNode("DATA");
        if (node_data)
        {
            // Models
            TextParser::NODE *node_models = node_data->FindChild("MODELS");
            if (node_models)
            {
                for(size_t i=0;i<node_models->children.size();i++)
                {
                    TextParser::NODE *child = node_models->children[i];
                    TextParser::NODE *node_filename = NULL;
                    if ( child->name == "MODEL" && 
                        (node_filename = child->FindChild("FILENAME")))
                    {   // MODEL
                        Model *model = new Model(node_filename->values[0].GetCharPtr());
                        TextParser::NODE *node_position = child->FindChild("POSITION");
                        if (node_position) model->SetPosition(node_position->ToFVector3());
                        TextParser::NODE *node_scale = child->FindChild("SCALE");
                        if (node_scale) model->SetScale(node_scale->ToFVector3());
                        TextParser::NODE *node_rotation = child->FindChild("ROTATION");
                        if (node_rotation) model->SetRotation(node_rotation->ToFVector3());
                        mModels.push_back(model);
                    }
                }
            }

            // Lights
            TextParser::NODE *node_lights = node_data->FindChild("LIGHTS");
            if (node_lights)
            {
                for(size_t i=0;i<node_lights->children.size();i++)
                {
                    Light *light = NULL;
                    TextParser::NODE *child = node_lights->children[i];
                    TextParser::NODE *node_type = child->FindChild("TYPE");
                    if (node_type->values[0] == "Point")
                    {
                        light = new PointLight();
                    }
                    else if (node_type->values[0] == "Directional")
                    {
                        light = new DirectionalLight();
                    }
                    else if (node_type->values[0] == "Ambient")
                    {
                        light = new AmbientLight();
                    }
                    if (!light) continue;
                    TextParser::NODE *node_color = child->FindChild("COLOR");
                    if (node_color)
                    {
                        light->SetColor(node_color->ToFVector3());
                    }
                    TextParser::NODE *node_intensity = child->FindChild("INTENSITY");
                    if (node_intensity)
                    {
                        light->SetIntensity(node_intensity->values[0].ToFloat());
                    }
                    TextParser::NODE *node_pos = child->FindChild("POSITION");
                    if (node_pos && light->GetType() == Light::TYPE_POINT)
                    {
                        ((PointLight*)light)->SetPosition(node_pos->ToFVector3());
                    }
                    TextParser::NODE *node_scl = child->FindChild("SCALE");
                    if (node_scl && light->GetType() == Light::TYPE_POINT)
                    {
                        ((PointLight*)light)->SetScale(node_scl->ToFVector3());
                    }
                    switch(light->GetType())
                    {
                    case Light::TYPE_POINT:
                        {
                            TextParser::NODE *node_range = child->FindChild("RANGE");
                            if (node_range)
                            {
                                ((PointLight*)light)->SetRange(node_range->values[0].ToFloat());
                            }
                            TextParser::NODE *node_exp = child->FindChild("EXPONENT");
                            if (node_exp)
                            {
                                ((PointLight*)light)->SetExponent(node_exp->values[0].ToFloat());
                            }
                        } break;
                    }
                    AddLight(light);
                }
            }
        }
    }
}