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

Method update

code/main/Bar.ts:35–139  ·  view source on GitHub ↗
(ratio: number, text: string = "")

Source from the content-addressed store, hash-verified

33
34 // Public methods
35 public update(ratio: number, text: string = ""): boolean{
36 var bordersBool: boolean;
37 var lateralBordersBool: boolean;
38 var textBool : boolean;
39 var contentY1: number;
40 var contentY2: number;
41 var contentSize: number;
42 var colorType: ColorType;
43
44 // If we have no height, we return
45 if(this.getHeight() <= 0)
46 return false;
47
48 // If the width is really to low, we return
49 if(this.getWidth() <= 1)
50 return false;
51
52 // We remove all the tags and all the text
53 this.removeAllTags();
54 this.eraseEverything();
55
56 // We decide if there will be text or not..
57 if(text.length != 0) // If there is at least one character in the text to draw
58 textBool = true;
59 else
60 textBool = false;
61
62 // We decide if there will be borders or not..
63 if(this.getHeight() < (textBool? 4 : 3)) // If the height is 1 or 2 without text, no borders / if the height is 1 or 2 or 3 with text, no borders
64 bordersBool = false;
65 else // Else, borders
66 bordersBool = true;
67
68 // ..and where the real content of the bar will take place
69 if(bordersBool){
70 contentY1 = 1;
71 if(textBool) contentY2 = this.getHeight() - 3;
72 else contentY2 = this.getHeight() - 2;
73 }
74 else{
75 contentY1 = 0;
76 if(textBool && this.getHeight() > 1) contentY2 = this.getHeight() - 2;
77 else contentY2 = this.getHeight() - 1;
78 }
79
80 // We decide if there will be lateral borders
81 if(this.getWidth() >= 20)
82 lateralBordersBool = true;
83 else
84 lateralBordersBool = false;
85
86 // We possibly draw the lateral borders
87 if(lateralBordersBool){
88 for(var i = contentY1; i <= contentY2; i++){
89 this.drawString("|", 0, i);
90 this.drawString("|", this.getWidth()-1, i);
91 }
92 }

Callers 2

updateHealthBarMethod · 0.45
clickedMethod · 0.45

Calls 7

removeAllTagsMethod · 0.80
eraseEverythingMethod · 0.80
drawStringMethod · 0.80
drawHorizontalLineMethod · 0.80
addBackgroundColorMethod · 0.80
getHeightMethod · 0.45
getWidthMethod · 0.45

Tested by

no test coverage detected