MCPcopy Create free account
hub / github.com/cocos/cocos-engine / strToColor

Function strToColor

cocos/tiledmap/tmx-xml-parser.ts:71–88  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

69}
70
71function strToColor (value: string): Color {
72 if (!value) {
73 return new Color(0, 0, 0, 255);
74 }
75 value = (value.indexOf('#') !== -1) ? value.substring(1) : value;
76 if (value.length === 8) {
77 const a = parseInt(value.substr(0, 2), 16) || 255;
78 const r = parseInt(value.substr(2, 2), 16) || 0;
79 const g = parseInt(value.substr(4, 2), 16) || 0;
80 const b = parseInt(value.substr(6, 2), 16) || 0;
81 return new Color(r, g, b, a);
82 } else {
83 const r = parseInt(value.substr(0, 2), 16) || 0;
84 const g = parseInt(value.substr(2, 2), 16) || 0;
85 const b = parseInt(value.substr(4, 2), 16) || 0;
86 return new Color(r, g, b, 255);
87 }
88}
89
90function getPropertyList (node: Element, map?: PropertiesInfo): PropertiesInfo {
91 const res: any[] = [];

Callers 4

getPropertyListFunction · 0.85
_parseImageLayerMethod · 0.85
_parseLayerMethod · 0.85
_parseObjectGroupMethod · 0.85

Calls 4

parseIntFunction · 0.85
substringMethod · 0.80
substrMethod · 0.80
indexOfMethod · 0.45

Tested by

no test coverage detected