Skip to content

Commit 85199cc

Browse files
committed
Rename type aliases to ImageSheets and Actions
Potentially these won't be `std::map` types in a future update. We should probably avoid naming things based on types. That is especially true when refactoring may change the underlying type.
1 parent cdafdda commit 85199cc

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

NAS2D/Resource/AnimationSet.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ namespace
4040
return " (Row: " + std::to_string(row) + ")";
4141
}
4242

43-
using ImageSheetMap = AnimationSet::ImageSheetMap;
44-
using ActionsMap = AnimationSet::ActionsMap;
43+
using ImageSheets = AnimationSet::ImageSheets;
44+
using Actions = AnimationSet::Actions;
4545

4646

47-
std::tuple<ImageSheetMap, ActionsMap> processXml(const std::string& filePath, ImageCache& imageCache);
48-
ImageSheetMap processImageSheets(const std::string& basePath, const Xml::XmlElement* element, ImageCache& imageCache);
49-
ActionsMap processActions(const ImageSheetMap& imageSheetMap, const Xml::XmlElement* element, ImageCache& imageCache);
50-
std::vector<AnimationSet::Frame> processFrames(const ImageSheetMap& imageSheetMap, const Xml::XmlElement* element, ImageCache& imageCache);
47+
std::tuple<ImageSheets, Actions> processXml(const std::string& filePath, ImageCache& imageCache);
48+
ImageSheets processImageSheets(const std::string& basePath, const Xml::XmlElement* element, ImageCache& imageCache);
49+
Actions processActions(const ImageSheets& imageSheets, const Xml::XmlElement* element, ImageCache& imageCache);
50+
std::vector<AnimationSet::Frame> processFrames(const ImageSheets& imageSheets, const Xml::XmlElement* element, ImageCache& imageCache);
5151
}
5252

5353

@@ -68,17 +68,17 @@ AnimationSet::AnimationSet(std::string fileName) :
6868

6969

7070
AnimationSet::AnimationSet(std::string fileName, ImageCache& imageCache) :
71-
mImageSheetMap{},
71+
mImageSheets{},
7272
mActions{}
7373
{
74-
auto [imageSheetMap, actions] = processXml(fileName, imageCache);
75-
mImageSheetMap = std::move(imageSheetMap);
74+
auto [imageSheets, actions] = processXml(fileName, imageCache);
75+
mImageSheets = std::move(imageSheets);
7676
mActions = std::move(actions);
7777
}
7878

7979

80-
AnimationSet::AnimationSet(ImageSheetMap imageSheetMap, ActionsMap actions) :
81-
mImageSheetMap{std::move(imageSheetMap)},
80+
AnimationSet::AnimationSet(ImageSheets imageSheets, Actions actions) :
81+
mImageSheets{std::move(imageSheets)},
8282
mActions{std::move(actions)}
8383
{
8484
}
@@ -109,7 +109,7 @@ namespace
109109
*
110110
* \param filePath File path of the sprite XML definition file.
111111
*/
112-
std::tuple<ImageSheetMap, ActionsMap> processXml(const std::string& filePath, ImageCache& imageCache)
112+
std::tuple<ImageSheets, Actions> processXml(const std::string& filePath, ImageCache& imageCache)
113113
{
114114
try
115115
{
@@ -144,9 +144,9 @@ namespace
144144
// Here instead of going through each element and calling a processing function to handle
145145
// it, we just iterate through all nodes to find sprite sheets. This allows us to define
146146
// image sheets anywhere in the sprite file.
147-
auto imageSheetMap = processImageSheets(basePath, xmlRootElement, imageCache);
148-
auto actions = processActions(imageSheetMap, xmlRootElement, imageCache);
149-
return std::tuple{std::move(imageSheetMap), std::move(actions)};
147+
auto imageSheets = processImageSheets(basePath, xmlRootElement, imageCache);
148+
auto actions = processActions(imageSheets, xmlRootElement, imageCache);
149+
return std::tuple{std::move(imageSheets), std::move(actions)};
150150
}
151151
catch (const std::runtime_error& error)
152152
{
@@ -163,9 +163,9 @@ namespace
163163
* element in a sprite definition, these elements can appear
164164
* anywhere in a Sprite XML definition.
165165
*/
166-
ImageSheetMap processImageSheets(const std::string& basePath, const Xml::XmlElement* element, ImageCache& imageCache)
166+
ImageSheets processImageSheets(const std::string& basePath, const Xml::XmlElement* element, ImageCache& imageCache)
167167
{
168-
ImageSheetMap imageSheetMap;
168+
ImageSheets imageSheets;
169169

170170
for (const auto* node = element->firstChildElement("imagesheet"); node; node = node->nextSiblingElement("imagesheet"))
171171
{
@@ -183,27 +183,27 @@ namespace
183183
throw std::runtime_error("Sprite imagesheet definition has `src` of length zero: " + endTag(node->row()));
184184
}
185185

186-
if (imageSheetMap.find(id) != imageSheetMap.end())
186+
if (imageSheets.find(id) != imageSheets.end())
187187
{
188188
throw std::runtime_error("Sprite image sheet redefinition: id: '" + id + "' " + endTag(node->row()));
189189
}
190190

191191
const auto imagePath = basePath + src;
192-
imageSheetMap.try_emplace(id, imagePath);
192+
imageSheets.try_emplace(id, imagePath);
193193
imageCache.load(imagePath);
194194
}
195195

196-
return imageSheetMap;
196+
return imageSheets;
197197
}
198198

199199

200200
/**
201201
* Iterates through all elements of a Sprite XML definition looking
202202
* for 'action' elements and processes them.
203203
*/
204-
ActionsMap processActions(const ImageSheetMap& imageSheetMap, const Xml::XmlElement* element, ImageCache& imageCache)
204+
Actions processActions(const ImageSheets& imageSheets, const Xml::XmlElement* element, ImageCache& imageCache)
205205
{
206-
ActionsMap actions;
206+
Actions actions;
207207

208208
for (const auto* action = element->firstChildElement("action"); action; action = action->nextSiblingElement("action"))
209209
{
@@ -219,7 +219,7 @@ namespace
219219
throw std::runtime_error("Sprite Action redefinition: '" + actionName + "' " + endTag(action->row()));
220220
}
221221

222-
actions[actionName] = processFrames(imageSheetMap, action, imageCache);
222+
actions[actionName] = processFrames(imageSheets, action, imageCache);
223223

224224
if (actions[actionName].empty())
225225
{
@@ -234,7 +234,7 @@ namespace
234234
/**
235235
* Parses through all <frame> tags within an <action> tag in a Sprite Definition.
236236
*/
237-
std::vector<AnimationSet::Frame> processFrames(const ImageSheetMap& imageSheetMap, const Xml::XmlElement* element, ImageCache& imageCache)
237+
std::vector<AnimationSet::Frame> processFrames(const ImageSheets& imageSheets, const Xml::XmlElement* element, ImageCache& imageCache)
238238
{
239239
std::vector<AnimationSet::Frame> frameList;
240240

@@ -258,8 +258,8 @@ namespace
258258
{
259259
throw std::runtime_error("Sprite Frame definition has 'sheetid' of length zero: " + endTag(currentRow));
260260
}
261-
const auto iterator = imageSheetMap.find(sheetId);
262-
if (iterator == imageSheetMap.end())
261+
const auto iterator = imageSheets.find(sheetId);
262+
if (iterator == imageSheets.end())
263263
{
264264
throw std::runtime_error("Sprite Frame definition references undefined imagesheet: '" + sheetId + "' " + endTag(currentRow));
265265
}

NAS2D/Resource/AnimationSet.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ namespace NAS2D
3838
bool isStopFrame() const;
3939
};
4040

41-
using ImageSheetMap = std::map<std::string, std::string>;
42-
using ActionsMap = std::map<std::string, std::vector<Frame>>;
41+
using ImageSheets = std::map<std::string, std::string>;
42+
using Actions = std::map<std::string, std::vector<Frame>>;
4343

4444

4545
explicit AnimationSet(std::string fileName);
4646
AnimationSet(std::string fileName, ResourceCache<Image, std::string>& imageCache);
47-
AnimationSet(ImageSheetMap imageSheetMap, ActionsMap actions);
47+
AnimationSet(ImageSheets imageSheets, Actions actions);
4848

4949
std::vector<std::string> actionNames() const;
5050
const std::vector<Frame>& frames(const std::string& actionName) const;
5151

5252
private:
53-
ImageSheetMap mImageSheetMap;
54-
ActionsMap mActions;
53+
ImageSheets mImageSheets;
54+
Actions mActions;
5555
};
5656

5757
} // namespace

0 commit comments

Comments
 (0)