mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-18 12:29:42 +00:00
move StringBank to BBGE
This commit is contained in:
parent
3a96c775db
commit
ce4f6a7d3e
26 changed files with 196 additions and 168 deletions
|
@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "Core.h"
|
||||
#include "SDL.h"
|
||||
#include "GameKeyNames.h"
|
||||
#include "StringBank.h"
|
||||
|
||||
|
||||
static std::string inputcode2string(int k)
|
||||
|
@ -142,10 +143,7 @@ std::string getInputCodeToUserString(unsigned int k, size_t joystickID)
|
|||
}
|
||||
|
||||
std::string s = inputcode2string(k);
|
||||
return s.empty() ? "•" : s; // Ø •
|
||||
// Actually, • looks interesting.
|
||||
// It shows up as a box, presumably because the font doesn't have that character.
|
||||
// I'll leave this as it is, because those boxes are kinda cool. -- fg
|
||||
return s.empty() ? stringbank.get(2153) : s;
|
||||
}
|
||||
|
||||
static int checkInp(const char *s, int category, int limit, const char *err)
|
||||
|
|
77
BBGE/StringBank.cpp
Normal file
77
BBGE/StringBank.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright (C) 2007, 2010 - Bit-Blot
|
||||
|
||||
This file is part of Aquaria.
|
||||
|
||||
Aquaria is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "StringBank.h"
|
||||
#include "ttvfs_stdio.h"
|
||||
|
||||
StringBank stringbank;
|
||||
static const std::string emptyStr;
|
||||
|
||||
StringBank::StringBank()
|
||||
{
|
||||
}
|
||||
|
||||
void StringBank::clear()
|
||||
{
|
||||
stringMap.clear();
|
||||
}
|
||||
|
||||
bool StringBank::empty() const
|
||||
{
|
||||
return stringMap.empty();
|
||||
}
|
||||
|
||||
bool StringBank::load(const std::string &file)
|
||||
{
|
||||
InStream in(file.c_str());
|
||||
if(!in)
|
||||
return false;
|
||||
|
||||
std::string line;
|
||||
int idx;
|
||||
|
||||
while (in >> idx)
|
||||
{
|
||||
std::getline(in, line);
|
||||
|
||||
if (!line.empty() && line[0] == ' ')
|
||||
line = line.substr(1, line.size());
|
||||
for (size_t i = 0; i < line.size(); i++)
|
||||
{
|
||||
if (line[i] == '|')
|
||||
line[i] = '\n';
|
||||
}
|
||||
stringMap[idx] = line;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string& StringBank::get(int idx) const
|
||||
{
|
||||
StringMap::const_iterator it = stringMap.find(idx);
|
||||
return it != stringMap.end() ? it->second : emptyStr;
|
||||
}
|
||||
|
||||
void StringBank::addDefault(int idx, const char *str)
|
||||
{
|
||||
StringMap::iterator it = stringMap.find(idx);
|
||||
if(it == stringMap.end())
|
||||
stringMap[idx] = str;
|
||||
}
|
25
BBGE/StringBank.h
Normal file
25
BBGE/StringBank.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef STRINGBANK_H
|
||||
#define STRINGBANK_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class StringBank
|
||||
{
|
||||
public:
|
||||
StringBank();
|
||||
bool load(const std::string &file);
|
||||
void clear();
|
||||
bool empty() const;
|
||||
void addDefault(int idx, const char *str);
|
||||
|
||||
const std::string& get(int idx) const;
|
||||
protected:
|
||||
|
||||
typedef std::map<int, std::string> StringMap;
|
||||
StringMap stringMap;
|
||||
};
|
||||
|
||||
extern StringBank stringbank;
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue