cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
1
|
//
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
2
|
// ToyTimerActionParser.cpp
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
3
4
5
6
7
8
|
// WattsenglishToyApp-mobile
//
// Created by Katarzyna Kalinowska-Górska on 28/12/2019.
//
#include <stdio.h>
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
9
10
11
|
#include "ToyTimerActionParser.h"
#include "ToyJSONParseUtils.h"
#include "ToyValueStorage.h"
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
12
13
14
|
// main parse function
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
15
|
cocos2d::Action* ToyTimerActionParser::parseJSONAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished)
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
16
17
|
{
cocos2d::Action* parsedAction = NULL;
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
18
|
if(ToyJSONParseUtils::hasMemberString(jsonActionObject, "actionType")){
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
std::string actionType = jsonActionObject["actionType"].GetString();
if(actionType == "startTimer"){
parsedAction = this->parseStartTimerAction(jsonActionObject, parseDelegate, notifyDelegateWhenFinished);
}
else if(actionType == "stopTimer"){
parsedAction = this->parseStopTimerAction(jsonActionObject, parseDelegate, notifyDelegateWhenFinished);
}
}
return parsedAction;
}
// functions for parsing differenct actions
/*
"actionType" = "startTimer"
"seconds" [float]
"onProgressActions" : [],
"onTimeUpActions" : [],
"finishScenarioAfterTimeUp" : true,
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
40
|
"timeIndicatorObject" : "timeSlider" //needs to conform to the ToyTimeIndicatorInterface
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
41
42
|
*/
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
43
|
cocos2d::Action* ToyTimerActionParser::parseStartTimerAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished)
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
44
|
{
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
45
|
if(ToyJSONParseUtils::hasMemberFloat(jsonActionObject, "seconds")){
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
46
47
48
49
50
|
float seconds = jsonActionObject["seconds"].GetFloat();
if(notifyDelegateWhenFinished){
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
51
|
auto storedValueKey = ToyValueStorage::getInstance().storeValue(jsonActionObject, parseDelegate->getToyValueStorageContainerName());
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
52
53
54
|
auto actionFunction = [](float pSeconds, std::string pStoredValueKey, ActionParseDelegate* pParseDelegate){
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
55
56
|
auto storedValue = ToyValueStorage::getInstance().getStoredValue(pStoredValueKey, pParseDelegate->getToyValueStorageContainerName());
ToyScenarioObject* sliderObject = ToyActionParser::getInstance().parseObject("timeIndicatorObject", pParseDelegate);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
57
58
59
60
61
62
63
64
65
66
67
68
69
|
if(sliderObject != nullptr){
//TODO
}
static int keyModifier = 0;
static int modulus = 100;
static std::string keyBase = "startTimerAction";
std::string key = keyBase + std::to_string((++keyModifier)%modulus);
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
70
|
// auto action = ToyActionParser::getInstance().parseJSONAction(array[i], parseDelegate, false);
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
71
72
73
|
pParseDelegate->scheduleOnce(std::bind([](float, std::string p2StoredValueKey, ActionParseDelegate* p2ParseDelegate){
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
74
75
|
p2ParseDelegate->actionFinished(*ToyValueStorage::getInstance().getStoredValue(p2StoredValueKey, p2ParseDelegate->getToyValueStorageContainerName()));
ToyValueStorage::getInstance().removeStoredValue(p2StoredValueKey, p2ParseDelegate->getToyValueStorageContainerName()); // if the callback is unscheduled, this will not be called. However, when the scene changes, the ToyValueStorage is always cleared.
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
}, std::placeholders::_1, pStoredValueKey, pParseDelegate), pSeconds, key);
};
return cocos2d::CallFunc::create(std::bind(actionFunction, seconds, storedValueKey, parseDelegate));
}
return cocos2d::DelayTime::create(seconds);
}
return nullptr;
}
/*
"actionType" = "stopTimer"
*/
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
93
|
cocos2d::Action* ToyTimerActionParser::parseStopTimerAction(const rapidjson::Value& jsonActionObject, ActionParseDelegate* parseDelegate, bool notifyDelegateWhenFinished)
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
94
|
{
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
95
|
// auto storedValueKey = ToyValueStorage::getInstance().storeValue(jsonActionObject, parseDelegate->getToyValueStorageContainerName());
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
96
97
98
|
//
// auto actionFunction = [&](std::string pStoredValueKey, ActionParseDelegate* pParseDelegate){
//
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
99
|
// auto storedJsonActionObject = ToyValueStorage::getInstance().getStoredValue(pStoredValueKey, pParseDelegate->getToyValueStorageContainerName());
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
100
|
//
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
101
|
// if(ToyActionParser::getInstance().checkLateCondition(*storedJsonActionObject, pParseDelegate)){
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
102
|
//
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
103
|
// if(ToyJSONParseUtils::hasMemberString(*storedJsonActionObject, "objectClass") && ToyJSONParseUtils::hasMemberString(*storedJsonActionObject, "objectName")){
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
104
105
106
107
108
109
|
// DynamicObjectMapper mapper;
// auto newObject = mapper.createObjectFromClassName((*storedJsonActionObject)["objectClass"].GetString(), *storedJsonActionObject, pParseDelegate);
// pParseDelegate->addNewObject((*storedJsonActionObject)["objectName"].GetString(), newObject);
// }
// }
//
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
110
|
// ToyValueStorage::getInstance().removeStoredValue(pStoredValueKey, pParseDelegate->getToyValueStorageContainerName());
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
111
112
113
114
|
// };
//TODO !!!!!! --->
// return this->finalizeParseActionWithActionFunction(jsonActionObject, parseDelegate, notifyDelegateWhenFinished, std::bind(actionFunction, storedValueKey, parseDelegate));
|
5daad4bc
xiaoyu
游戏源码添加编译(现存问题:游戏内...
|
115
|
return nullptr;
|
cb213901
xiaoyu
添加一个游戏的源码和编译选项
|
116
117
|
}
|