25 if (part.bone().empty()) {
26 return absl::InvalidArgumentError(
"a part has no bone to move with");
28 const std::string& bone = part.bone();
29 switch (part.shape()) {
30 case figures::Part::SHAPE_LIMB:
31 if (part.to().empty() || part.start_radius() <= 0.0f ||
32 part.end_radius() <= 0.0f) {
33 return absl::InvalidArgumentError(absl::StrCat(
34 "a limb on the ", bone,
" needs an end, and a radius at each"));
36 return absl::OkStatus();
37 case figures::Part::SHAPE_BALL:
38 if (part.size().x() <= 0.0f || part.size().y() <= 0.0f ||
39 part.size().z() <= 0.0f) {
40 return absl::InvalidArgumentError(
41 absl::StrCat(
"a ball on the ", bone,
" needs a size each way"));
43 return absl::OkStatus();
45 return absl::InvalidArgumentError(
46 absl::StrCat(
"a part on the ", bone,
" has no shape"));
50absl::StatusOr<figures::Figures>
ParseFigures(std::string_view text) {
51 figures::Figures file;
52 const absl::Status parsed =
ParseText(text, file);
56 for (
const figures::Part& part : file.body()) {
57 const absl::Status checked =
CheckPart(part);
62 for (
const figures::Hair& hair : file.hairs()) {
63 for (
const figures::Part& part : hair.parts()) {
64 const absl::Status checked =
CheckPart(part);
66 return absl::InvalidArgumentError(
67 absl::StrCat(
"a way to wear the hair: ", checked.message()));
78 const uint32_t mixed =
id * 2654435761u;
79 auto pick = [&](
int count,
int byte) {
80 return static_cast<int>((mixed >> (8 * byte)) % count);
83 if (!figures.skins().empty()) {
84 features.
skin = figures.skins(pick(figures.skins_size(), 1));
86 if (!figures.hair_colors().empty()) {
88 figures.hair_colors(pick(figures.hair_colors_size(), 2));
90 if (!figures.hairs().empty()) {
91 features.
hair = pick(figures.hairs_size(), 3);
97 const google::protobuf::RepeatedPtrField<figures::Part>& parts) {
98 std::vector<figures::Part> unfolded;
99 for (
const figures::Part& part : parts) {
100 unfolded.push_back(part);
101 if (!part.mirrored()) {
104 figures::Part right = part;
105 right.set_bone(ToTheRight(part.bone()));
106 right.set_from(ToTheRight(part.from()));
107 right.set_to(ToTheRight(part.to()));
108 right.mutable_from_offset()->set_x(-part.from_offset().x());
109 right.mutable_to_offset()->set_x(-part.to_offset().x());
110 unfolded.push_back(right);