示例#1
0
// -----------------------------------------------------------------------
// SelectLongOperation
// -----------------------------------------------------------------------
SelectLongOperation::SelectLongOperation(RLMachine& machine,
                                         const SelectElement& commandElement)
    : machine_(machine),
      return_value_(-1) {
  const vector<SelectElement::Param>& params = commandElement.getRawParams();
  for (unsigned int i = 0; i < params.size(); ++i) {
    Option o;
    o.shown = true;

    std::string evaluated_native =
        libReallive::evaluatePRINT(machine, params[i].text);
    o.str = cp932toUTF8(evaluated_native, machine.getTextEncoding());

    std::vector<SelectElement::Condition> conditions = params[i].cond_parsed;
    for (std::vector<SelectElement::Condition>::const_iterator it =
             conditions.begin(); it != conditions.end(); ++it) {
      switch (it->effect) {
        // TODO(erg): Someday, I might need to support the other options, but
        // for now, I've never seen anything other than hide.
        case SelectElement::OPTION_HIDE: {
          bool value = false;
          if (it->condition != "") {
            const char* location = it->condition.c_str();
            scoped_ptr<ExpressionPiece> condition(
              libReallive::get_expression(location));
            value = !condition->integerValue(machine);
          }

          o.shown = value;
          break;
        }
        default:
          cerr << "Unsupported option in select statement: "
               << it->effect << endl;
          break;
      }
    }

    options_.push_back(o);
  }
}
示例#2
0
SaveGameListModel::SaveGameListModel(const std::string& no_data,
                                     RLMachine& machine) {
    using namespace boost::posix_time;

    // TODO: Can I make this faster instead of trying to see if every game
    // exists?
    int latestSlot = -1;
    time_t latestTime = numeric_limits<time_t>::min();

    for (int slot = 0; slot < 100; ++slot) {
        fs::path saveFile = Serialization::buildSaveGameFilename(machine, slot);

        ostringstream oss;
        oss << "[" << setw(3) << setfill('0') << slot << "] ";

        bool file_exists = fs::exists(saveFile);
        if (file_exists) {
            SaveGameHeader header = Serialization::loadHeaderForSlot(machine, slot);
            oss << to_simple_string(header.save_time) << " - "
                << cp932toUTF8(header.title, machine.getTextEncoding());

            time_t mtime = fs::last_write_time(saveFile);

            if (mtime > latestTime) {
                latestTime = mtime;
                latestSlot = slot;
            }
        } else {
            oss << no_data;
        }

        titles_.push_back(std::make_pair(oss.str(), file_exists));
    }

    if (latestSlot != -1) {
        titles_[latestSlot].first = "[NEW] " + titles_[latestSlot].first;
    }
}