private static BasicGame ParseGameFromFile(string filename, bool loadLevelsFromGameTree) { var gamedef = Resources.Load <TextAsset>(filename); if (gamedef == null) { Debug.LogError("Failed to load game: " + filename); return(null); } return(VGDLParser.ParseGame(gamedef.text, loadLevelsFromGameTree)); }
public override void Validate(VGDLGame game) { base.Validate(game); if (string.IsNullOrEmpty(ftype)) { throw new ArgumentException("Missing ftype in addTimer definition!"); } //Also check whether the type exists! VGDLParser.eval(ftype); }
protected VGDLSprite createAndAddSpriteAt(string stype, Vector2 position, bool force = false) { if (num_sprites > MAX_SPRITES) { Debug.LogWarning("Sprite limit reached."); return(null); } if (!spriteContructors.ContainsKey(stype)) { Debug.LogWarning("Sprite definition for [" + stype + "] not found!"); return(null); } if (VGDLParser.verbose) { Debug.Log("Creating sprite [" + stype + "] at position (" + position.x + "," + position.y + ")"); } if (string.IsNullOrEmpty(spriteContructors[stype].sclass)) { Debug.LogError("Can't initialize abstract sprite types: " + stype + " has no Sprite class"); } // Check for singleton Sprites if (!force) { foreach (var type in spriteContructors[stype].stypes) { // If this type is a singleton and we have one already if (spriteContructors.ContainsKey(type) && spriteContructors[type].args.ContainsKey("singleton") && spriteContructors[type].args["singleton"].CompareAndIgnoreCase("TRUE") && getNumberOfSprites(type) > 0) { // that's it, no more creations of this type. if (VGDLParser.verbose) { Debug.Log("Sprite limit reached for " + stype); } return(null); } } } var spriteSize = new Vector2(block_size, block_size); //TODO: consider templates. //Create sprite var newSprite = VGDLParser.CreateInstance <VGDLSprite>(spriteContructors[stype].sclass, spriteContructors[stype].args); //set position and size newSprite.types = spriteContructors[stype].stypes; newSprite.init(position, spriteSize); addSprite(stype, newSprite); newSprite.name = stype + "_" + newSprite.spriteID; //If new sprite is a resource, update the resource dictionaries. var res = newSprite as Resource; if (res != null) { resourceLimits[res.resource_name] = res.limit; resourceColors[res.resource_name] = res.color; } return(newSprite); }
private BasicGame parseGameFromString(string gamestr) { return(VGDLParser.ParseGame(gamestr, loadLevelsFromGameTree)); }