Added inventory scroll + minor refactor
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
using std::string;
|
||||
|
||||
void BinaryWriter::put(ubyte b) {
|
||||
buffer.push_back(b);
|
||||
}
|
||||
@@ -18,7 +16,7 @@ void BinaryWriter::putCStr(const char* str) {
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryWriter::put(const string& s) {
|
||||
void BinaryWriter::put(const std::string& s) {
|
||||
size_t len = s.length();
|
||||
if (len > INT16_MAX) {
|
||||
throw std::domain_error("length > INT16_MAX");
|
||||
@@ -27,7 +25,7 @@ void BinaryWriter::put(const string& s) {
|
||||
put((const ubyte*)s.data(), len);
|
||||
}
|
||||
|
||||
void BinaryWriter::putShortStr(const string& s) {
|
||||
void BinaryWriter::putShortStr(const std::string& s) {
|
||||
size_t len = s.length();
|
||||
if (len > 255) {
|
||||
throw std::domain_error("length > 255");
|
||||
@@ -144,22 +142,22 @@ float BinaryReader::getFloat32() {
|
||||
return value.valfloat;
|
||||
}
|
||||
|
||||
string BinaryReader::getString() {
|
||||
std::string BinaryReader::getString() {
|
||||
uint16_t length = (uint16_t)getInt16();
|
||||
if (pos+length > size) {
|
||||
throw std::underflow_error("unexpected end");
|
||||
}
|
||||
pos += length;
|
||||
return string((const char*)(data+pos-length), length);
|
||||
return std::string((const char*)(data+pos-length), length);
|
||||
}
|
||||
|
||||
string BinaryReader::getShortString() {
|
||||
std::string BinaryReader::getShortString() {
|
||||
ubyte length = get();
|
||||
if (pos+length > size) {
|
||||
throw std::underflow_error("unexpected end");
|
||||
}
|
||||
pos += length;
|
||||
return string((const char*)(data+pos-length), length);
|
||||
return std::string((const char*)(data+pos-length), length);
|
||||
}
|
||||
|
||||
bool BinaryReader::hasNext() const {
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "../coders/toml.h"
|
||||
#include "../coders/json.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||
std::unique_ptr<toml::Wrapper> wrapper (new toml::Wrapper());
|
||||
toml::Section& display = wrapper->add("display");
|
||||
@@ -47,7 +45,7 @@ toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||
return wrapper.release();
|
||||
}
|
||||
|
||||
string write_controls() {
|
||||
std::string write_controls() {
|
||||
json::JObject* obj = new json::JObject();
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
@@ -64,7 +62,7 @@ string write_controls() {
|
||||
return json::stringify(obj, true, " ");
|
||||
}
|
||||
|
||||
void load_controls(string filename, string source) {
|
||||
void load_controls(std::string filename, std::string source) {
|
||||
json::JObject* obj = json::parse(filename, source);
|
||||
for (auto& entry : Events::bindings) {
|
||||
auto& binding = entry.second;
|
||||
@@ -73,7 +71,7 @@ void load_controls(string filename, string source) {
|
||||
if (jentry == nullptr)
|
||||
continue;
|
||||
inputtype type;
|
||||
string typestr;
|
||||
std::string typestr;
|
||||
jentry->str("type", typestr);
|
||||
|
||||
if (typestr == "keyboard") {
|
||||
@@ -87,4 +85,4 @@ void load_controls(string filename, string source) {
|
||||
binding.type = type;
|
||||
jentry->num("code", binding.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user