From bf9bccc30a186e338f96c230a4f63cc924c77bd8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Jun 2011 23:23:30 +0300 Subject: Add ability to add comments to any players. --- src/being.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index d45bbcf74..508f56aef 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -216,7 +216,9 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): mMinHit(0), mMaxHit(0), mCriticalHit(0), - mPvpRank(0) + mPvpRank(0), + mComment(""), + mGotComment(false) { mSpriteRemap = new int[20]; mSpriteHide = new int[20]; @@ -236,6 +238,8 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): if (getType() == PLAYER) mShowName = config.getBoolValue("visiblenames"); + else + mGotComment = true; config.addListener("visiblenames", this); @@ -2251,6 +2255,41 @@ void Being::clearCache() beingInfoCache.clear(); } +void Being::updateComment() +{ + if (mGotComment || mName.empty()) + return; + + mGotComment = true; + mComment = loadComment(mName); +} + +std::string Being::loadComment(const std::string &name) +{ + std::string str = Client::getUsersDirectory() + + stringToHexPath(name) + "/comment.txt"; + std::vector lines; + + ResourceManager *resman = ResourceManager::getInstance(); + if (resman->existsLocal(str)) + { + lines = resman->loadTextFileLocal(str); + if (lines.size() >= 2) + return lines[1]; + } + return ""; +} + +void Being::saveComment(const std::string &name, + const std::string &comment) +{ + std::string dir = Client::getUsersDirectory() + + stringToHexPath(name); + std::string fileName = dir + "/comment.txt"; + ResourceManager *resman = ResourceManager::getInstance(); + resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); +} + BeingEquipBackend::BeingEquipBackend(Being *being): mBeing(being) { -- cgit v1.2.3-70-g09d2