コード例 #1
0
    public VGDLGame()
    {
        //default sprite constructors need to be added for wall and avatar.
        var wallArgs = new Dictionary <string, string>();

        wallArgs.Add("color", "DARKGRAY");
        wallArgs.Add("solid", "True");
        var wallInfo = new VGDLSpriteInfo("wall", "Immovable", wallArgs, new List <string> {
            "wall"
        });

        var avatarArgs = new Dictionary <string, string>();
        var avatarInfo = new VGDLSpriteInfo("avatar", "MovingAvatar", avatarArgs, new List <string> {
            "avatar"
        });

        registerSpriteConstructor("wall", wallInfo);
        registerSpriteConstructor("avatar", avatarInfo);

        updateSubTypes(new List <string> {
            "wall"
        }, "wall");
        updateSubTypes(new List <string> {
            "avatar"
        }, "avatar");
    }
コード例 #2
0
    public void registerSpriteConstructor(string key, VGDLSpriteInfo spriteInfo)
    {
        //NOTE: new sprite constructors with the same key will override previous definitions
        if (spriteContructors.ContainsKey(key))
        {
            //Ignore wall and avatar overrides, otherwise Log a warning
            if (!key.CompareAndIgnoreCase("wall") && !key.CompareAndIgnoreCase("avatar"))
            {
                Debug.LogWarning("Sprite [" + key + "] is defined multiple times, the last one will be used.");
            }
        }

        spriteContructors[key] = spriteInfo;
        //subTypes[key] = spriteInfo.stypes;

        //Also add the sprite group
        if (!spriteGroups.ContainsKey(key))
        {
            spriteGroups[key] = new List <VGDLSprite>();
        }
    }
コード例 #3
0
ファイル: VGDLParser.cs プロジェクト: sysnet-ai/UnityVGDL
    /// <summary>
    /// Parse sprite set
    /// </summary>
    /// <param name="game"></param>
    /// <param name="childChildren"></param>
    /// <param name="parentClass"></param>
    /// <param name="parentArgs"></param>
    /// <param name="parentKeys"></param>
    /// <exception cref="ArgumentException"></exception>
    private static void parseSprites(BasicGame game, IEnumerable <VGDLNode> childChildren, string parentClass = null, Dictionary <string, string> parentArgs = null, List <string> parentKeys = null)
    {
        foreach (var node in childChildren)
        {
            if (!node.content.Contains(">"))
            {
                throw new ArgumentException("Sprite error on line: " + node.lineNumber +
                                            "\nSprite def should be in the form: spriteName > (SomeSpriteType paramX=5 etc.)");
            }

            if (verbose)
            {
                Debug.Log("Parsing sprite from: " + node.content + "\nLine: " + node.lineNumber);
            }

            List <string> stypes;
            if (parentKeys == null)
            {
                stypes = new List <string>();
            }
            else
            {
                stypes = new List <string>(parentKeys);
            }

            var spriteDef = node.content.Split('>');

            var key  = spriteDef[0].Trim();
            var sdef = spriteDef[1].Trim();

            if (verbose && parentClass != null)
            {
                var parameters = string.Join(",", parentArgs.Select(item => item.ToString()).ToArray());
                Debug.Log(key + " parentClass " + parentClass + " and arguments (" + parameters + ")");
            }

            var typeAndArgs = parseArgs(sdef, parentClass, parentArgs);

            stypes.Add(key);

            //Leaf types update subtypes of all parent types.
            game.updateSubTypes(stypes, key);

            //NOTE: ignoring singletons for now, only reason for it to exist
            //is to keep the designer from spawning multiple of them.
            //And the only function that sounds like it would use it in the JAVA framework,
            //doesn't actually check it (TransformToSingleton),
            //even the sprite defs in the only game that uses it don't set the singleton parameter.
            //eg. singleton parameter is overhead that no one uses.

            if (node.children.Any())
            {
                //Add the type unless it's an abstract type (eg. has no class definition)
                if (!string.IsNullOrEmpty(typeAndArgs.sclass))
                {
                    if (verbose)
                    {
                        var parameters = string.Join(",", typeAndArgs.args.Select(item => item.ToString()).ToArray());
                        Debug.LogFormat("Defining: {0} as type {1} with parameters ({2}) and parsing it's subtree!", key, typeAndArgs.sclass, parameters);
                    }

                    var spriteInfo = new VGDLSpriteInfo(key, typeAndArgs.sclass, typeAndArgs.args, stypes);
                    game.registerSpriteConstructor(key, spriteInfo);

                    game.addOrUpdateKeyInSpriteOrder(key);
                }


                parseSprites(game, node.children, typeAndArgs.sclass, typeAndArgs.args, stypes);
            }
            else //leaf node
            {
                if (verbose)
                {
                    var parameters = string.Join(",", typeAndArgs.args.Select(item => item.ToString()).ToArray());
                    Debug.LogFormat("Defining: {0} as type {1} with parameters ({2})", key, typeAndArgs.sclass, parameters);
                }

                var spriteInfo = new VGDLSpriteInfo(key, typeAndArgs.sclass, typeAndArgs.args, stypes);
                game.registerSpriteConstructor(key, spriteInfo);

                game.addOrUpdateKeyInSpriteOrder(key);
            }
        }
    }