Exemple #1
0
//追加
void SqliteManager::addPicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string cols = "";
    std::string values = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        cols.append('\''+(*it).first+'\'');
        cols.append(",");

        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }

    std::string create_at = "created_at";
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //作成時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    //更新時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    cols.pop_back();
    values.pop_back();

    std::string sql = "INSERT INTO "+ table_name +" (" + cols + ") VALUES (" + values + ")";
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
Exemple #2
0
//更新
void SqliteManager::savePicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string values = "";
    std::string update_id = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        values.append('\''+(*it).first+'\'');
        values.append("=");


        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        if ((*it).first == "id") {
            update_id = value;
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //更新時間
    values.append('\''+updated_at+'\'');
    values.append("=");
    values.append(now_time);

    std::string sql = "UPDATE "+ table_name +" SET " + values + " WHERE id = " + update_id;
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
  EarthViewer(const Vec2<int>& size, const float scale, const bool oblong, Touch& touch, Keyinp& keyinp, const std::string& path, const std::string& lang) :
    touch_(touch),
    keyinp_(keyinp),
    size_(size.x / scale, size.y / scale),
    params_(path + "devdata/params.json"),
    scale_(scale),
    aspect_((float)size.x / (float)size.y),
    camera_(Camera::PERSPECTIVE),
    cockpit_(Camera::ORTHOGONAL),
    localize_(lang, path),
    earth_(params_.value().get<picojson::object>()["earth"].get<picojson::object>(), path, camera_),
    rotate_mix_(),
    place_index_()
  {
    DOUT << "EarthViewer()" << std::endl;

    picojson::object& params = params_.value().get<picojson::object>();

    camera_.oblong(oblong);
    SetupCamera(camera_, params["camera"].get<picojson::object>(), aspect_);
    cockpit_.setSize(size.x / scale, size.y / scale);

    {
      picojson::array& array = params["lights"].get<picojson::array>();
      for (picojson::array::iterator it = array.begin(); it != array.end(); ++it)
      {
        Light light;
        SetupLight(light, it->get<picojson::object>());
        lights_.push_back(light);
      }
      earth_.light(lights_);
    }

    env_.touch       = &touch_;
    env_.keyinp      = &keyinp_;
    env_.path        = &path;
    env_.savePath    = &path;
    env_.size        = &size_;
    env_.scale       = scale_;
    env_.params      = &params_;
    env_.task        = &task_;
    env_.camera      = &camera_;
    env_.cockpit     = &cockpit_;
    env_.earth       = &earth_;
    env_.earthLight  = &lights_[0];
    env_.fonts       = &fonts_;
    env_.texMng      = &texMng_;
    env_.localize    = &localize_;

    env_.earth_texture = 0;
    earth_.texture(env_.earth_texture);
    earth_.setRotSpeed(0);

    {
      const std::string& file = params["game"].get<picojson::object>()["places"].get<std::string>();
      Json places = Json(path + file);
      places_ = places.value().get<picojson::object>();
      for (picojson::object::iterator it = places_.begin(); it != places_.end(); ++it)
      {
        place_names_.push_back(&it->first);
      }
    }

    task_.add<Control>(TASK_PRIO_SYS, env_);
    task_.add<Game2DSetup>(TASK_PRIO_2D_TOPPRIO, env_);
    task_.add<GameWorld>(TASK_PRIO_3D_TOPPRIO, env_);
    env_.task->add<PlaceDisp>(TASK_PRIO_2D, env_);
    // task_.add<Equator>(TASK_PRIO_3D, env_);
    task_.add<TouchEft>(TASK_PRIO_3D, env_);
  }