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

Method _parseObjectGroup

cocos/tiledmap/tmx-xml-parser.ts:911–1019  ·  view source on GitHub ↗
(selGroup: Element)

Source from the content-addressed store, hash-verified

909 }
910
911 protected _parseObjectGroup (selGroup: Element): TMXObjectGroupInfo {
912 const objectGroup = new TMXObjectGroupInfo();
913 objectGroup.name = selGroup.getAttribute('name') || '';
914 objectGroup.offset = new Vec2(parseFloat(selGroup.getAttribute('offsetx')!), parseFloat(selGroup.getAttribute('offsety')!));
915
916 const opacity = selGroup.getAttribute('opacity');
917 if (opacity) objectGroup.opacity = Math.round(255 * parseFloat(opacity));
918 else objectGroup.opacity = 255;
919
920 const tintColor = selGroup.getAttribute('tintcolor');
921 objectGroup.tintColor = tintColor ? strToColor(tintColor) : null;
922
923 const visible = selGroup.getAttribute('visible');
924 if (visible && parseInt(visible) === 0) objectGroup.visible = false;
925
926 const color = selGroup.getAttribute('color');
927 if (color) objectGroup.color.fromHEX(color);
928
929 const draworder = selGroup.getAttribute('draworder');
930 if (draworder) objectGroup.draworder = draworder as any;
931
932 // set the properties to the group
933 objectGroup.setProperties(getPropertyList(selGroup));
934
935 const objects = selGroup.getElementsByTagName('object');
936 if (objects) {
937 for (let j = 0; j < objects.length; j++) {
938 const selObj = objects[j];
939 // The value for "type" was blank or not a valid class name
940 // Create an instance of TMXObjectInfo to store the object and its properties
941 const objectProp: TMXObject = {} as any;
942
943 // Set the id of the object
944 objectProp.id = selObj.getAttribute('id') || j;
945
946 // Set the name of the object to the value for "name"
947 objectProp.name = selObj.getAttribute('name') || '';
948
949 // Assign all the attributes as key/name pairs in the properties dictionary
950 objectProp.width = parseFloat(selObj.getAttribute('width')!) || 0;
951 objectProp.height = parseFloat(selObj.getAttribute('height')!) || 0;
952
953 objectProp.x = parseFloat(selObj.getAttribute('x')!) || 0;
954 objectProp.y = parseFloat(selObj.getAttribute('y')!) || 0;
955
956 objectProp.rotation = parseFloat(selObj.getAttribute('rotation')!) || 0;
957
958 objectProp.properties = getPropertyList(selObj);
959
960 // visible
961 const visibleAttr = selObj.getAttribute('visible');
962 objectProp.visible = !(visibleAttr && parseInt(visibleAttr) === 0);
963
964 // text
965 const texts = selObj.getElementsByTagName('text');
966 if (texts && texts.length > 0) {
967 const text = texts[0];
968 objectProp.type = TMXObjectType.TEXT;

Callers 1

parseXMLStringMethod · 0.95

Calls 14

setPropertiesMethod · 0.95
_parsePointsStringMethod · 0.95
parseFloatFunction · 0.85
strToColorFunction · 0.85
parseIntFunction · 0.85
getPropertyListFunction · 0.85
strToHAlignFunction · 0.85
strToVAlignFunction · 0.85
fromHEXMethod · 0.80
getElementsByTagNameMethod · 0.80
getAttributeMethod · 0.45
roundMethod · 0.45

Tested by

no test coverage detected