-
Notifications
You must be signed in to change notification settings - Fork 11
/
Animation.cpp
157 lines (131 loc) · 4.77 KB
/
Animation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "Animation.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
bool Animation::matchesFilter(std::string filterStr){
std::vector<std::string> filterTokens = StringUtils::split(filterStr, ' ');
FILTER_OPERATORS currentFitlerOperator = FILTER_OR;
bool matchesFilter = true;
int nrMatches = 0;
for (auto token : filterTokens) {
if (!token.empty() && (token.compare("AND") == 0 || token.compare("and") == 0)) {
currentFitlerOperator = FILTER_AND;
continue;
}
else if (!token.empty() && (token.compare("OR") == 0 || token.compare("or") == 0)) {
currentFitlerOperator = FILTER_OR;
continue;
}
else if (!token.empty() && (token.compare("NOT") == 0 || token.compare("not") == 0)) {
currentFitlerOperator = FILTER_NOT;
continue;
}
if (currentFitlerOperator == FILTER_AND) {
if (std::string(animName).find(token) == std::string::npos && std::string(animLibrary).find(token) == std::string::npos) {
return false;
}
}
else if (currentFitlerOperator == FILTER_NOT) {
if (std::string(animName).find(token) != std::string::npos || std::string(animLibrary).find(token) != std::string::npos) {
return false;
}
}
else {//FILTER_OR
if (std::string(animName).find(token) != std::string::npos || std::string(animLibrary).find(token) != std::string::npos) {
nrMatches++;
}
}
}
if (nrMatches > 0) {
return true;
}
else {
return false;
}
/*if (std::string(animName).find(filterStr) != std::string::npos || std::string(animLibrary).find(filterStr) != std::string::npos) {
return true;
}
else {
return false;
}*/
}
std::vector<AnimationFlag> gtaAnimationFlags = {
{ "Normal",ANIMATION_LOOP_FLAG1 },
{ "Controllable*",ANIMATION_LOOP_FLAG1 | ANIMATION_ALLOW_MOVEMENT_FLAG6 | ANIMATION_UPPER_BODY_FLAG5 },
{ "Facial",ANIMATION_LOOP_FLAG1 | ANIMATION_ALLOW_MOVEMENT_FLAG6 },
{ "Stop on movement",ANIMATION_LOOP_FLAG1 | ANIMATION_STOP_ON_MOVEMENT_FLAG8 },
{ "Crazy #1",ANIMATION_LOOP_FLAG1 | ANIMATION_CRAZY_FLAG9 },
{ "Crazy #2",ANIMATION_LOOP_FLAG1 | ANIMATION_FLAG14 },
/*
{ "Test 1",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 },
{ "Test 7",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG7},
{ "Test 10",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG10 },
{ "Test 11",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG11 },
{ "Test 12",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG12 },
{ "Test 13",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG13 },
{ "Test 14", ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG14 },
{ "Test 15",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG15 },
{ "Test 16",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG16 },
{ "Test 17",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG17 },
{ "Test 18",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG18 },
{ "Test 19",ANIMATION_LOOP_FLAG1 | ANIMATION_UPPER_BODY_FLAG5 | ANIMATION_FLAG19 },*/
};
std::vector<Animation> gtaAnimations ={
{ 0,"00000","","",0 }
};
std::vector<Animation> getAllAnimations() {
return gtaAnimations;
}
bool initAnimations(std::string fileName) {
gtaAnimations.reserve(21883);
std::ifstream animationsFile;
animationsFile.open(fileName);
if (!animationsFile){
return false;
}
int index = 1;
std::string strShortcutIndex;
std::string animLibrary;
std::string animName;
int duration;
while (animationsFile >> strShortcutIndex >> animLibrary >> animName >> duration)
{
gtaAnimations.push_back({ index,strShortcutIndex,strdup(animLibrary.c_str()),strdup(animName.c_str()),duration });
index++;
}
return true;
}
Animation getAnimationForShortcutIndex(int index) {
if (index > 0 && index < gtaAnimations.size()) {
return gtaAnimations[index];
}
else {
//0 is the null animation
return gtaAnimations[0];
}
}
Animation getAnimationForShortcutIndex(std::string strIndex) {
strIndex.erase(0, strIndex.find_first_not_of('0'));
int index = atoi(strIndex.c_str());
return getAnimationForShortcutIndex(index);
}
std::vector<AnimationFlag> getAnimationFlags() {
return gtaAnimationFlags;
}
AnimationFlag getDefaultAnimationFlag() {
return gtaAnimationFlags[0];
}
AnimationFlag getNextAnimationFlag(AnimationFlag animationFlag) {
//see http://stackoverflow.com/questions/14225932/search-for-a-struct-item-in-a-vector-by-member-data
int foundIndex = std::find_if(gtaAnimationFlags.begin(), gtaAnimationFlags.end(), [=](AnimationFlag const& flag) {
return (flag.id == animationFlag.id);
}) - gtaAnimationFlags.begin();
if (foundIndex + 1 >= gtaAnimationFlags.size()) {//color not found or in last element
return gtaAnimationFlags[0];
}
else {
return gtaAnimationFlags[foundIndex + 1];
}
}