Crossfire Server, Trunk
Facesets.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020-2021 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "Facesets.h"
14 
15 extern "C" {
16 #include "string.h"
17 }
18 
20  auto found = std::find_if(m_assets.begin(), m_assets.end(), [&id] (const auto fs) {
21  return fs.second->id == id;
22  });
23  return found == m_assets.end() ? nullptr : found->second;
24 }
25 
26 face_sets *Facesets::create(const std::string& prefix) {
27  auto fs = static_cast<face_sets *>(calloc(1, sizeof(face_sets)));
28  fs->prefix = strdup_local(prefix.c_str());
29  return fs;
30 }
31 
33  free(item->prefix);
34  free(item->fullname);
35  free(item->size);
36  free(item->extension);
37  free(item->comment);
38  free(item->faces);
39  free(item);
40 }
41 
42 void Facesets::replace(face_sets *existing, face_sets *update) {
43  auto id = existing->id;
44  free(existing->prefix);
45  free(existing->fullname);
46  free(existing->size);
47  free(existing->extension);
48  free(existing->comment);
49  if (update->allocated) {
50  free(existing->faces);
51  } else {
52  free(update->faces);
53  update->faces = existing->faces;
54  update->allocated = existing->allocated;
55  }
56  *existing = *update;
57  existing->id = id;
58  free(update);
59 }
60 
62  face->id = m_assets.size() - 1;
63 }
castle_read.prefix
string prefix
Definition: castle_read.py:31
Facesets::create
virtual face_sets * create(const std::string &prefix)
Definition: Facesets.cpp:26
strdup_local
#define strdup_local
Definition: compat.h:29
Facesets.h
face_sets::allocated
size_t allocated
Definition: image.h:25
face_sets::id
int id
Definition: image.h:18
face_sets::prefix
char * prefix
Definition: image.h:19
face_sets::extension
char * extension
Definition: image.h:23
AssetsCollection< face_sets >::m_assets
std::map< std::string, face_sets * > m_assets
Definition: AssetsCollection.h:157
face_sets::comment
char * comment
Definition: image.h:24
Facesets::replace
virtual void replace(face_sets *existing, face_sets *update)
Definition: Facesets.cpp:42
Facesets::findById
face_sets * findById(int id)
Definition: Facesets.cpp:19
face_sets::size
char * size
Definition: image.h:22
Facesets::destroy
virtual void destroy(face_sets *item)
Definition: Facesets.cpp:32
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
item
Definition: item.py:1
face_sets::fullname
char * fullname
Definition: image.h:20
face_sets
Definition: image.h:17
Facesets::added
virtual void added(face_sets *face)
Definition: Facesets.cpp:61
face_sets::faces
face_info * faces
Definition: image.h:26
diamondslots.id
id
Definition: diamondslots.py:53