MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / drawString

Method drawString

code/main/RenderArea.ts:346–408  ·  view source on GitHub ↗
(str: string, x: number = 0, y: number = 0, translated: boolean = false, transparency: RenderTransparency = null)

Source from the content-addressed store, hash-verified

344 }
345
346 public drawString(str: string, x: number = 0, y: number = 0, translated: boolean = false, transparency: RenderTransparency = null): boolean{
347 var indexFirst: number;
348 var indexLast: number;
349
350 // BUGS (change position)
351 if(Bugs.getGraphicalBugLevel() >= 4){
352 x += Random.between(0, 20) - 10;
353 y += Random.between(0, 4) - 2;
354 }
355
356 // Return false if y is out of bounds
357 if(y < 0 || y >= this.height)
358 return false;
359
360 // BUGS (random character)
361 if(Bugs.getGraphicalBugLevel() >= 3)
362 str = Bugs.changeRandomCharacter(str);
363 else if(Bugs.getGraphicalBugLevel() >= 2 && Random.oneChanceOutOf(2))
364 str = Bugs.changeRandomCharacter(str);
365 else if(Bugs.getGraphicalBugLevel() >= 1 && Random.oneChanceOutOf(3))
366 str = Bugs.changeRandomCharacter(str);
367
368 // The indices of the first and last character we're going to draw
369 indexFirst = 0;
370 indexLast = str.length;
371
372 // Restrict the indices if out of bounds
373 if(x + indexLast >= this.width)
374 indexLast -= (x + indexLast - this.width);
375 if(x < 0)
376 indexFirst = -x;
377
378 // If there isn't even one character to draw, we return false
379 if(indexLast < 0 || indexFirst >= str.length)
380 return false;
381
382 // If there's no transparent character, we just draw the whole string
383 if(transparency == null){
384 this.area[y] = this.area[y].replaceAt(x + indexFirst, str.substring(indexFirst, indexLast));
385 }
386 // Else we draw characters one by one to avoid drawing transparent ones !
387 else{
388 for(var i = indexFirst; i < indexLast; i++){ // We iterate over characters
389 // If the character isn't alpha
390 if(str[i] != transparency.getAlphaCharacter()){
391 // If the meta alpha character isn't null and our character is this meta alpha character, we draw the alpha character
392 if(transparency.getMetaAlphaCharacter() != null && str[i] == transparency.getMetaAlphaCharacter())
393 this.area[y] = this.area[y].replaceAt(x + i, transparency.getAlphaCharacter());
394 // Else, we draw the character
395 else
396 this.area[y] = this.area[y].replaceAt(x + i, str[i]);
397 }
398 }
399 }
400
401 // If translated is true, add the tags
402 if(translated){
403 this.addTwoTags(x, x + str.length, y, "<span class=\"translated\">", "</span>");

Callers 15

addAsciiRealButtonMethod · 0.95
addEnigmaMethod · 0.95
addHtmlLinkMethod · 0.95
drawAreaMethod · 0.95
drawArrayMethod · 0.95
drawHorizontalLineMethod · 0.95
drawSpeechMethod · 0.95
drawVerticalLineMethod · 0.95
eraseEverythingMethod · 0.95
constructorMethod · 0.80
drawMethod · 0.80
drawPlayerSpellsMethod · 0.80

Calls 4

addTwoTagsMethod · 0.95
replaceAtMethod · 0.80
getAlphaCharacterMethod · 0.80
getMetaAlphaCharacterMethod · 0.80

Tested by

no test coverage detected