ldtypes.cpp

changeset 161
c9fba92c4e35
parent 160
edcb03f3ef75
child 162
b7d65e89861a
equal deleted inserted replaced
160:edcb03f3ef75 161:c9fba92c4e35
108 108
109 } 109 }
110 110
111 // ============================================================================= 111 // =============================================================================
112 str LDComment::getContents () { 112 str LDComment::getContents () {
113 return format ("0 %s", zText.chars ()); 113 return fmt ("0 %s", zText.chars ());
114 } 114 }
115 115
116 str LDSubfile::getContents () { 116 str LDSubfile::getContents () {
117 str val = format ("1 %d %s ", dColor, vPosition.stringRep (false).chars ()); 117 str val = fmt ("1 %d %s ", dColor, vPosition.stringRep (false).chars ());
118 val += mMatrix.stringRep (); 118 val += mMatrix.stringRep ();
119 val += ' '; 119 val += ' ';
120 val += zFileName; 120 val += zFileName;
121 return val; 121 return val;
122 } 122 }
123 123
124 str LDLine::getContents () { 124 str LDLine::getContents () {
125 str val = format ("2 %d", dColor); 125 str val = fmt ("2 %d", dColor);
126 126
127 for (ushort i = 0; i < 2; ++i) 127 for (ushort i = 0; i < 2; ++i)
128 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ()); 128 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ());
129 129
130 return val; 130 return val;
131 } 131 }
132 132
133 str LDTriangle::getContents () { 133 str LDTriangle::getContents () {
134 str val = format ("3 %d", dColor); 134 str val = fmt ("3 %d", dColor);
135 135
136 for (ushort i = 0; i < 3; ++i) 136 for (ushort i = 0; i < 3; ++i)
137 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ()); 137 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ());
138 138
139 return val; 139 return val;
140 } 140 }
141 141
142 str LDQuad::getContents () { 142 str LDQuad::getContents () {
143 str val = format ("4 %d", dColor); 143 str val = fmt ("4 %d", dColor);
144 144
145 for (ushort i = 0; i < 4; ++i) 145 for (ushort i = 0; i < 4; ++i)
146 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ()); 146 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ());
147 147
148 return val; 148 return val;
149 } 149 }
150 150
151 str LDCondLine::getContents () { 151 str LDCondLine::getContents () {
152 str val = format ("5 %d", dColor); 152 str val = fmt ("5 %d", dColor);
153 153
154 // Add the coordinates 154 // Add the coordinates
155 for (ushort i = 0; i < 4; ++i) 155 for (ushort i = 0; i < 4; ++i)
156 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ()); 156 val.appendformat (" %s", vaCoords[i].stringRep (false).chars ());
157 157
161 str LDGibberish::getContents () { 161 str LDGibberish::getContents () {
162 return zContents; 162 return zContents;
163 } 163 }
164 164
165 str LDVertex::getContents () { 165 str LDVertex::getContents () {
166 return format ("0 !LDFORGE VERTEX %d %s", dColor, vPosition.stringRep (false).chars()); 166 return fmt ("0 !LDFORGE VERTEX %d %s", dColor, vPosition.stringRep (false).chars());
167 } 167 }
168 168
169 str LDEmpty::getContents () { 169 str LDEmpty::getContents () {
170 return str (); 170 return str ();
171 } 171 }
181 "NOCERTIFY", 181 "NOCERTIFY",
182 "INVERTNEXT", 182 "INVERTNEXT",
183 }; 183 };
184 184
185 str LDBFC::getContents () { 185 str LDBFC::getContents () {
186 return format ("0 BFC %s", LDBFC::saStatements[eStatement]); 186 return fmt ("0 BFC %s", LDBFC::saStatements[eStatement]);
187 } 187 }
188 188
189 // ============================================================================= 189 // =============================================================================
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
191 // ============================================================================= 191 // =============================================================================
429 continue; 429 continue;
430 430
431 if (!firstDetails) 431 if (!firstDetails)
432 text += ", "; 432 text += ", ";
433 433
434 str noun = format ("%s%s", g_saObjTypeNames[objType], PLURAL (objCount)); 434 str noun = fmt ("%s%s", g_saObjTypeNames[objType], PLURAL (objCount));
435 435
436 // Plural of "vertex" is "vertices". Stupid English. 436 // Plural of "vertex" is "vertices". Stupid English.
437 if (objType == OBJ_Vertex && objCount != 1) 437 if (objType == OBJ_Vertex && objCount != 1)
438 noun = "vertices"; 438 noun = "vertices";
439 439
658 658
659 // ============================================================================= 659 // =============================================================================
660 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 660 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
661 // ============================================================================= 661 // =============================================================================
662 str LDRadial::getContents () { 662 str LDRadial::getContents () {
663 return format ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s", 663 return fmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s",
664 str (radialTypeName()).toupper ().strip (' ').chars (), 664 str (radialTypeName()).toupper ().strip (' ').chars (),
665 dColor, dSegments, dDivisions, dRingNum, 665 dColor, dSegments, dDivisions, dRingNum,
666 vPosition.stringRep (false).chars(), mMatrix.stringRep().chars()); 666 vPosition.stringRep (false).chars(), mMatrix.stringRep().chars());
667 } 667 }
668 668
692 dNumerator *= dFactor; 692 dNumerator *= dFactor;
693 dDenominator *= dFactor; 693 dDenominator *= dFactor;
694 } 694 }
695 695
696 // Compose some general information: prefix, fraction, root, ring number 696 // Compose some general information: prefix, fraction, root, ring number
697 str zPrefix = (dDivisions == 16) ? "" : format ("%d/", dDivisions); 697 str zPrefix = (dDivisions == 16) ? "" : fmt ("%d/", dDivisions);
698 str zFrac = format ("%d-%d", dNumerator, dDenominator); 698 str zFrac = fmt ("%d-%d", dNumerator, dDenominator);
699 str zRoot = g_saRadialNameRoots[eRadialType]; 699 str zRoot = g_saRadialNameRoots[eRadialType];
700 str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? format ("%d", dRingNum) : ""; 700 str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? fmt ("%d", dRingNum) : "";
701 701
702 // Truncate the root if necessary (7-16rin4.dat for instance). 702 // Truncate the root if necessary (7-16rin4.dat for instance).
703 // However, always keep the root at least 2 characters. 703 // However, always keep the root at least 2 characters.
704 short dExtra = (~zFrac + ~zRingNum + ~zRoot) - 8; 704 short dExtra = (~zFrac + ~zRingNum + ~zRoot) - 8;
705 zRoot -= min<short> (max<short> (dExtra, 0), 2); 705 zRoot -= min<short> (max<short> (dExtra, 0), 2);
706 706
707 // Stick them all together and return the result. 707 // Stick them all together and return the result.
708 return format ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ()); 708 return fmt ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ());
709 } 709 }
710 710
711 // ============================================================================= 711 // =============================================================================
712 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 712 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
713 // ============================================================================= 713 // =============================================================================

mercurial