Esempio n. 1
0
        public static LHSprite nodeWithDictionary(PlistDictionary dict, CCNode prnt)
        {
            LHScene scene = ((LHNodeProtocol)prnt).getScene();

            string imageFileName     = dict ["imageFileName"].AsString;
            string relativeImagePath = dict ["relativeImagePath"].AsString;


//			string imagePath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (false));
//			string imageDevPath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (true));

            string imagePath    = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(false));
            string imageDevPath = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(true));


            CCTexture2D texture = scene.textureWithImagePath(imagePath);

            CCSpriteFrame spriteFrame = null;

            string imageFilePath   = imageDevPath;
            string spriteFrameName = dict["spriteName"].AsString;

            if (spriteFrameName != null)
            {
                LHSprite.cacheSpriteFramesInfo(imageDevPath, scene);
                spriteFrame = CCSpriteFrameCache.SharedSpriteFrameCache [spriteFrameName];
            }
            else
            {
                //spriteFrame = [texture createSpriteFrame];
            }

            LHSprite spr = new LHSprite(spriteFrame, dict, prnt, spriteFrameName, imageDevPath);


            return(spr);
        }
        public void loadPhysicsInfoFromDictionary(PlistDictionary dict, CCNode nd)
        {
            _node = nd;

            if (null != dict)
            {
                int shapeType = dict ["shape"].AsInt;
                int type      = dict ["type"].AsInt;

                LHScene scene = ((LHNodeProtocol)_node).getScene();

                b2World world = scene.getBox2dWorld();

                var bodyDef = new b2BodyDef();
                bodyDef.type = (b2BodyType)type;

                CCPoint position = _node.Parent.ConvertToWorldspace(_node.Position);
//				bodyDef.position = scene.metersFromPoint (position);
                bodyDef.position = new b2Vec2(position.X, position.Y);

                float angle = CCNodeTransforms.GlobalXAngleFromLocalAngle(_node, _node.RotationX);
                bodyDef.angle = LHUtils.LH_DEGREES_TO_RADIANS(angle);

                bodyDef.userData = _node;

                _body          = world.CreateBody(bodyDef);
                _body.UserData = _node;


                Debug.WriteLine("BODY:" + _body);


                _body.SetFixedRotation(dict ["fixedRotation"].AsBool);
                //_body->SetGravityScale

                _body.SetSleepingAllowed(dict ["allowSleep"].AsBool);
                _body.SetBullet(dict ["bullet"].AsBool);

                _body.AngularDamping  = dict ["angularDamping"].AsFloat;
                _body.AngularVelocity = -360.0f * dict ["angularVelocity"].AsFloat;
                _body.LinearDamping   = dict ["linearDamping"].AsFloat;

                CCPoint linearVel = CCPoint.Parse(dict ["linearVelocity"].AsString);
                _body.LinearVelocity = new b2Vec2(linearVel.X, linearVel.Y);


                CCSize size = _node.ContentSize;
//				size.Width = scene.metersFromValue (size.Width);
//				size.Height = scene.metersFromValue (size.Height);

                CCPoint scale = new CCPoint(_node.ScaleX, _node.ScaleY);
                scale = CCNodeTransforms.ConvertToWorldScale(_node, scale);

                previousScale = scale;


                size.Width  *= scale.X;
                size.Height *= scale.Y;


                PlistDictionary fixInfo = dict ["genericFixture"].AsDictionary;

                Debug.WriteLine("FIX INFO " + fixInfo);

                Debug.WriteLine("SHAPE TYPE " + shapeType);

                if (shapeType == 0)               //RECTANGLE
                {
                    LHBodyShape shape = new LHBodyShape();
                    shape.createRectangleWithDictionary(fixInfo, _body, _node, scene, size);

                    _subShapes.Add(shape);
                }
                else if (shapeType == 1)               //CIRCLE
                {
                    LHBodyShape shape = new LHBodyShape();
                    shape.createCircleWithDictionary(fixInfo, _body, _node, scene, size);

                    _subShapes.Add(shape);
                }
                else if (shapeType == 4)               //oval
                {
                    PlistArray shapePoints = dict ["ovalShape"].AsArray;
                    if (shapePoints != null)
                    {
                        LHBodyShape shape = new LHBodyShape();
                        shape.createShapeWithDictionary(fixInfo, shapePoints, _body, _node, scene, scale);
                        _subShapes.Add(shape);
                    }
                }
                else if (shapeType == 5)               //traced
                {
                    String fixUUID = dict ["fixtureUUID"].AsString;

                    Debug.WriteLine("TRACED " + fixUUID);

                    PlistArray shapePoints = scene.tracedFixturesWithUUID(fixUUID);

                    Debug.WriteLine("RETURNS " + shapePoints);

                    if (shapePoints == null)
                    {
                        //CHECK IN ASSET
                        //LHAsset asset = _node.assetParent;
                        ///
                    }

                    if (shapePoints != null)
                    {
                        LHBodyShape shape = new LHBodyShape();

                        Debug.WriteLine("WE HAVE A TRACED SHAPE");

                        shape.createShapeWithDictionary(fixInfo, shapePoints, _body, _node, scene, scale);

                        _subShapes.Add(shape);
                    }
                }
                else if (shapeType == 6)               //editor
                {
                    LHSprite sprite = (LHSprite)_node;


                    if (sprite != null && sprite.GetType() == typeof(LHSprite))
                    {
                        String imageFile = sprite.getImageFilePath();

                        imageFile = LHUtils.stripExtension(imageFile);

                        Debug.WriteLine("WE HAVE AN EDITOR SHAPE for sprite " + sprite + " node " + _node + " tst " + imageFile);


                        PlistDictionary bodyInfo = scene.getEditorBodyInfoForSpriteName(sprite.getSpriteFrameName(), imageFile);

                        Debug.WriteLine("WE HAVE BODY INFO " + bodyInfo);

                        if (bodyInfo != null)
                        {
                            PlistArray fixturesInfo = bodyInfo ["shapes"].AsArray;

                            for (int i = 0; i < fixturesInfo.Count; ++i)
                            {
                                PlistDictionary shapeInfo = fixturesInfo [i].AsDictionary;

                                Debug.WriteLine("SHAPE INFO " + shapeInfo);

                                LHBodyShape shape = new LHBodyShape();

                                shape.createEditorWithDictionary(shapeInfo, _body, _node, scene, scale);

                                _subShapes.Add(shape);
                            }
                        }
                    }
                }

//				if (dict.ContainsKey ("alpha")) {
//					_node.Opacity = (byte)dict ["alpha"].AsFloat;
//				}
            }
        }
        public static CCNode createLHNodeWithDictionary(PlistDictionary childInfo, CCNode prnt)
        {
            string nodeType = childInfo["nodeType"].AsString;

            LHScene scene = ((LHNodeProtocol)prnt).getScene();

            string subclassNodeType = childInfo["subclassNodeType"].AsString;

            if (subclassNodeType != null && subclassNodeType.Length > 0)
            {
                //TODO handle subclasses

                //this will not work as we do not have the class included in the api
//				Class classObj = [scene createNodeObjectForSubclassWithName:subclassNodeType superTypeName:nodeType];
//				if(classObj){
//					return [classObj nodeWithDictionary:childInfo parent:prnt];
//				}
//				else{
//					NSLog(@"\n\nWARNING: Expected a class of type %@ subclassed from %@, but nothing was returned. Check your \"createNodeObjectForSubclassWithName:superTypeName:\" method and make sure you return a valid Class.\n\n", subclassNodeType, nodeType);
//				}
            }

            if (nodeType == "LHGameWorldNode")
            {
                LHGameWorldNode pNode = LHGameWorldNode.nodeWithDictionary(childInfo, prnt);
                pNode.ContentSize = scene._designResolutionSize;
//				#if LH_DEBUG
//				[pNode setDebugDraw:YES];
//				#endif
                return(pNode);
            }
            else if (nodeType == "LHBackUINode")
            {
                LHBackUINode pNode = LHBackUINode.nodeWithDictionary(childInfo, prnt);
                return(pNode);
            }
            else if (nodeType == "LHUINode")
            {
                LHUINode pNode = LHUINode.nodeWithDictionary(childInfo, prnt);
                return(pNode);
            }
            else if (nodeType == "LHSprite")
            {
                LHSprite spr = LHSprite.nodeWithDictionary(childInfo, prnt);
                return(spr);
            }
//			else if([nodeType isEqualToString:@"LHNode"])
//			{
//				LHNode* nd = [LHNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return nd;
//			}
//			else if([nodeType isEqualToString:@"LHBezier"])
//			{
//				LHBezier* bez = [LHBezier nodeWithDictionary:childInfo
//					parent:prnt];
//				return bez;
//			}
//			else if([nodeType isEqualToString:@"LHTexturedShape"])
//			{
//				LHShape* sp = [LHShape nodeWithDictionary:childInfo
//					parent:prnt];
//				return sp;
//			}
//			else if([nodeType isEqualToString:@"LHWaves"])
//			{
//				LHWater* wt = [LHWater nodeWithDictionary:childInfo
//					parent:prnt];
//				return wt;
//			}
//			else if([nodeType isEqualToString:@"LHAreaGravity"])
//			{
//				LHGravityArea* gv = [LHGravityArea nodeWithDictionary:childInfo
//					parent:prnt];
//				return gv;
//			}
//			else if([nodeType isEqualToString:@"LHParallax"])
//			{
//				LHParallax* pr = [LHParallax nodeWithDictionary:childInfo
//					parent:prnt];
//				return pr;
//			}
//			else if([nodeType isEqualToString:@"LHParallaxLayer"])
//			{
//				LHParallaxLayer* lh = [LHParallaxLayer nodeWithDictionary:childInfo
//					parent:prnt];
//				return lh;
//			}
//			else if([nodeType isEqualToString:@"LHAsset"])
//			{
//				LHAsset* as = [LHAsset nodeWithDictionary:childInfo
//					parent:prnt];
//				return as;
//			}
//			else if([nodeType isEqualToString:@"LHCamera"])
//			{
//				LHCamera* cm = [LHCamera nodeWithDictionary:childInfo
//					parent:prnt];
//				return cm;
//			}
//			else if([nodeType isEqualToString:@"LHRopeJoint"])
//			{
//				LHRopeJointNode* jt = [LHRopeJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHWeldJoint"])
//			{
//				LHWeldJointNode* jt = [LHWeldJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHRevoluteJoint"]){
//
//				LHRevoluteJointNode* jt = [LHRevoluteJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHDistanceJoint"]){
//
//				LHDistanceJointNode* jt = [LHDistanceJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//
//			}
//			else if([nodeType isEqualToString:@"LHPulleyJoint"]){
//
//				LHPulleyJointNode* jt = [LHPulleyJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHPrismaticJoint"]){
//
//				LHPrismaticJointNode* jt = [LHPrismaticJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHWheelJoint"]){
//
//				LHWheelJointNode* jt = [LHWheelJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//			else if([nodeType isEqualToString:@"LHGearJoint"]){
//
//				LHGearJointNode* jt = [LHGearJointNode nodeWithDictionary:childInfo
//					parent:prnt];
//				return jt;
//			}
//
//
//			else{
//				NSLog(@"UNKNOWN NODE TYPE %@", nodeType);
//			}

            return(null);
        }