Skip to content

Commit ed270e6

Browse files
committed
hotfix export setting return error
1 parent 0f8c7a9 commit ed270e6

File tree

2 files changed

+102
-112
lines changed

2 files changed

+102
-112
lines changed

content/setting/setting.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
Game:
2-
FPS: 60 # min 1
3-
RandomSeed: -1 # -1: use random seed
4-
Physic:
5-
PhysicFrameRate: 60 # min 0
6-
Friction: 0.85 # [0, 1] : 0 no friction, 1 max friction
1+
- Game:
2+
FPS: 60
3+
RandomSeed: -1
4+
- Physic:
5+
PhysicFrameRate: 60
6+
Bounciness: 0.6
77
GravityX: 0
88
GravityY: 9.81
9-
Bounciness: 0.6 # [0, 1] : 0 no bounciness, 1 full energie restitution
10-
ContinuousCollisionMaxVelocity: 40 # min 0
11-
FootBasementWidth: 6 # min 2
12-
FootBasementHeight: 2 # min 2
13-
CollisionPixelRatioStopMovement: 0.3 # min 0, max 1. Ratio of pixel with collision to detect a real collision
14-
IsGroundedDetection: 1.0 # min 0
15-
InputReleaseImpulse: 1.0 # min 0. Velocity factor after release the pet
16-
GamePlay:
17-
CoyoteTimeCursorMovement: 0.05 # min 0. Record duration of the velocity before released the pet to preserve velocity with the mouse movement
18-
Window:
19-
FullScreenWindow: true # Initialize the window size and position in full screen based on the first monitor
20-
ShowFrameBufferBackground: false # Define if window background should be visible
21-
UseForwardWindow: true # Define if the application should be displayed in forground
22-
ShowWindow: false # Display the window edge or not
23-
UseMousePassThoughWindow: true # Define if user can selection pet only with selected pixel or with the entire windows
24-
Style:
9+
Friction: 0.85
10+
ContinuousCollisionMaxVelocity: 40
11+
FootBasementWidth: 6
12+
FootBasementHeight: 2
13+
CollisionPixelRatioStopMovement: 0.3
14+
IsGroundedDetection: 1
15+
InputReleaseImpulse: 1
16+
- GamePlay:
17+
CoyoteTimeCursorMovement: 0.05
18+
- Window:
19+
FullScreenWindow: true
20+
ShowWindow: false
21+
ShowFrameBufferBackground: false
22+
UseForwardWindow: true
23+
UseMousePassThoughWindow: true
24+
- Style:
2525
Theme: PetForDesktop
26-
Accessibility:
26+
- Accessibility:
2727
Scale: 2
2828
TextScale: 1
29-
Debug:
30-
ShowEdgeDetection: false # Debug mode to display the result of the collision alogyrthm on the entire window
29+
- Debug:
30+
ShowEdgeDetection: false

src/Settings.cpp

Lines changed: 77 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,93 +7,82 @@
77

88
void Setting::importFile(const char* src, GameData& data)
99
{
10-
YAML::Node animGraph = YAML::LoadFile(src);
11-
if (!animGraph)
10+
YAML::Node root = YAML::LoadFile(src);
11+
if (!root)
1212
{
1313
errorAndExit(std::string("Could not find setting file here: ") + src);
1414
}
1515

16-
std::string section;
17-
{
18-
section = "Game";
19-
YAML::Node nodesSection = animGraph[section];
20-
if (!nodesSection)
21-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
22-
23-
data.FPS = std::max(nodesSection["FPS"].as<int>(), 1);
24-
data.randomSeed = nodesSection["RandomSeed"].as<int>();
25-
}
26-
27-
{
28-
section = "Physic";
29-
YAML::Node nodesSection = animGraph[section];
30-
if (!nodesSection)
31-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
32-
33-
data.physicFrameRate = std::max(nodesSection["PhysicFrameRate"].as<int>(), 0);
34-
data.bounciness = std::clamp(nodesSection["Bounciness"].as<float>(), 0.f, 1.f);
35-
data.gravity = Vec2{nodesSection["GravityX"].as<float>(), nodesSection["GravityY"].as<float>()};
36-
data.gravityDir = data.gravity.normalized();
37-
data.friction = std::clamp(nodesSection["Friction"].as<float>(), 0.f, 1.f);
38-
data.continuousCollisionMaxSqrVelocity =
39-
std::max(nodesSection["ContinuousCollisionMaxVelocity"].as<float>(), 0.f);
40-
data.continuousCollisionMaxSqrVelocity *= data.continuousCollisionMaxSqrVelocity;
41-
data.footBasementWidth = std::max(nodesSection["FootBasementWidth"].as<int>(), 2);
42-
data.footBasementHeight = std::max(nodesSection["FootBasementHeight"].as<int>(), 2);
43-
data.collisionPixelRatioStopMovement =
44-
std::clamp(nodesSection["CollisionPixelRatioStopMovement"].as<float>(), 0.f, 1.f);
45-
data.isGroundedDetection = std::max(nodesSection["IsGroundedDetection"].as<float>(), 0.f);
46-
data.releaseImpulse = std::max(nodesSection["InputReleaseImpulse"].as<float>(), 0.f);
47-
}
48-
49-
{
50-
section = "GamePlay";
51-
YAML::Node nodesSection = animGraph[section];
52-
if (!nodesSection)
53-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
54-
55-
data.coyoteTimeCursorPos = std::max(nodesSection["CoyoteTimeCursorMovement"].as<float>(), 0.f);
56-
}
57-
58-
{
59-
section = "Window";
60-
YAML::Node nodesSection = animGraph[section];
61-
if (!nodesSection)
62-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
63-
64-
data.fullScreenWindow = nodesSection["FullScreenWindow"].as<bool>();
65-
data.showWindow = nodesSection["ShowWindow"].as<bool>();
66-
data.showFrameBufferBackground = nodesSection["ShowFrameBufferBackground"].as<bool>();
67-
data.useForwardWindow = nodesSection["UseForwardWindow"].as<bool>();
68-
data.useMousePassThoughWindow = nodesSection["UseMousePassThoughWindow"].as<bool>();
69-
}
70-
71-
{
72-
section = "Style";
73-
YAML::Node nodesSection = animGraph[section];
74-
if (!nodesSection)
75-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
76-
77-
data.styleName = nodesSection["Theme"].as<std::string>();
78-
}
79-
80-
{
81-
section = "Accessibility";
82-
YAML::Node nodesSection = animGraph[section];
83-
if (!nodesSection)
84-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
85-
86-
data.scale = std::max(nodesSection["Scale"].as<int>(), 1);
87-
data.textScale = std::max(nodesSection["TextScale"].as<float>(), 1.f);
88-
}
89-
90-
{
91-
section = "Debug";
92-
YAML::Node nodesSection = animGraph[section];
93-
if (!nodesSection)
94-
errorAndExit("Cannot find \"" + section + "\" in setting.yaml");
95-
96-
data.debugEdgeDetection = nodesSection["ShowEdgeDetection"].as<bool>();
16+
YAML::Node nodesSection;
17+
for (auto roleIter = root.begin(); roleIter != root.end(); roleIter++)
18+
{
19+
nodesSection = (*roleIter)["Game"];
20+
if (nodesSection)
21+
{
22+
data.FPS = std::max(nodesSection["FPS"].as<int>(), 1);
23+
data.randomSeed = nodesSection["RandomSeed"].as<int>();
24+
continue;
25+
}
26+
27+
nodesSection = (*roleIter)["Physic"];
28+
if (nodesSection)
29+
{
30+
data.physicFrameRate = std::max(nodesSection["PhysicFrameRate"].as<int>(), 0);
31+
data.bounciness = std::clamp(nodesSection["Bounciness"].as<float>(), 0.f, 1.f);
32+
data.gravity = Vec2{nodesSection["GravityX"].as<float>(), nodesSection["GravityY"].as<float>()};
33+
data.gravityDir = data.gravity.normalized();
34+
data.friction = std::clamp(nodesSection["Friction"].as<float>(), 0.f, 1.f);
35+
data.continuousCollisionMaxSqrVelocity =
36+
std::max(nodesSection["ContinuousCollisionMaxVelocity"].as<float>(), 0.f);
37+
data.continuousCollisionMaxSqrVelocity *= data.continuousCollisionMaxSqrVelocity;
38+
data.footBasementWidth = std::max(nodesSection["FootBasementWidth"].as<int>(), 2);
39+
data.footBasementHeight = std::max(nodesSection["FootBasementHeight"].as<int>(), 2);
40+
data.collisionPixelRatioStopMovement =
41+
std::clamp(nodesSection["CollisionPixelRatioStopMovement"].as<float>(), 0.f, 1.f);
42+
data.isGroundedDetection = std::max(nodesSection["IsGroundedDetection"].as<float>(), 0.f);
43+
data.releaseImpulse = std::max(nodesSection["InputReleaseImpulse"].as<float>(), 0.f);
44+
continue;
45+
}
46+
47+
nodesSection = (*roleIter)["GamePlay"];
48+
if (nodesSection)
49+
{
50+
data.coyoteTimeCursorPos = std::max(nodesSection["CoyoteTimeCursorMovement"].as<float>(), 0.f);
51+
continue;
52+
}
53+
54+
nodesSection = (*roleIter)["Window"];
55+
if (nodesSection)
56+
{
57+
data.fullScreenWindow = nodesSection["FullScreenWindow"].as<bool>();
58+
data.showWindow = nodesSection["ShowWindow"].as<bool>();
59+
data.showFrameBufferBackground = nodesSection["ShowFrameBufferBackground"].as<bool>();
60+
data.useForwardWindow = nodesSection["UseForwardWindow"].as<bool>();
61+
data.useMousePassThoughWindow = nodesSection["UseMousePassThoughWindow"].as<bool>();
62+
continue;
63+
}
64+
65+
nodesSection = (*roleIter)["Style"];
66+
if (nodesSection)
67+
{
68+
data.styleName = nodesSection["Theme"].as<std::string>();
69+
continue;
70+
}
71+
72+
nodesSection = (*roleIter)["Accessibility"];
73+
if (nodesSection)
74+
{
75+
data.scale = std::max(nodesSection["Scale"].as<int>(), 1);
76+
data.textScale = std::max(nodesSection["TextScale"].as<float>(), 1.f);
77+
continue;
78+
}
79+
80+
nodesSection = (*roleIter)["Debug"];
81+
if (nodesSection)
82+
{
83+
data.debugEdgeDetection = nodesSection["ShowEdgeDetection"].as<bool>();
84+
continue;
85+
}
9786
}
9887
}
9988

@@ -107,7 +96,7 @@ void Setting::exportFile(const char* dest, GameData& data)
10796
}
10897

10998
YAML::Emitter out;
110-
99+
out << YAML::BeginSeq;
111100
std::string section;
112101
{
113102
section = "Game";
@@ -130,11 +119,12 @@ void Setting::exportFile(const char* dest, GameData& data)
130119
out << YAML::Key << "GravityX" << YAML::Value << YAML::Precision(4) << data.gravity.x;
131120
out << YAML::Key << "GravityY" << YAML::Value << YAML::Precision(4) << data.gravity.y;
132121
out << YAML::Key << "Friction" << YAML::Value << YAML::Precision(4) << data.friction;
133-
out << YAML::Key << "ContinuousCollisionMaxVelocity" << YAML::Value << std::sqrt(data.continuousCollisionMaxSqrVelocity);
122+
out << YAML::Key << "ContinuousCollisionMaxVelocity" << YAML::Value
123+
<< std::sqrt(data.continuousCollisionMaxSqrVelocity);
134124
out << YAML::Key << "FootBasementWidth" << YAML::Value << data.footBasementWidth;
135125
out << YAML::Key << "FootBasementHeight" << YAML::Value << data.footBasementHeight;
136126
out << YAML::Key << "CollisionPixelRatioStopMovement" << YAML::Value << YAML::Precision(4)
137-
<< data.collisionPixelRatioStopMovement;
127+
<< data.collisionPixelRatioStopMovement;
138128
out << YAML::Key << "IsGroundedDetection" << YAML::Value << data.isGroundedDetection;
139129
out << YAML::Key << "InputReleaseImpulse" << YAML::Value << data.releaseImpulse;
140130
out << YAML::EndMap;
@@ -195,7 +185,7 @@ void Setting::exportFile(const char* dest, GameData& data)
195185
out << YAML::EndMap;
196186
out << YAML::EndMap;
197187
}
198-
188+
out << YAML::EndSeq;
199189
fwrite(out.c_str(), sizeof(char), out.size(), file);
200190
fclose(file);
201191
}

0 commit comments

Comments
 (0)