コード例 #1
0
ファイル: ConfigParserXML.cs プロジェクト: yizhi401/NoahsArk
        public AvailableConfigurations Parse(
            string miscConfigTxt,
            string tilesConfigTxt,
            string avatarsConfigTxt,
            string itemsConfigTxt,
            string generatorsConfigTxt)
        {
            availableConfigs = new AvailableConfigurations();

            XmlElement miscConfig       = GetConfigXmlElement(miscConfigTxt);
            XmlElement tilesConfig      = GetConfigXmlElement(tilesConfigTxt);
            XmlElement avatarsConfig    = GetConfigXmlElement(avatarsConfigTxt);
            XmlElement itemsConfig      = GetConfigXmlElement(itemsConfigTxt);
            XmlElement generatorsConfig = GetConfigXmlElement(generatorsConfigTxt);

            List <ConfigWorldSize> sizes = new List <ConfigWorldSize>();

            foreach (XmlElement sizeXML in GetChildElements(miscConfig["Sizes"]))
            {
                sizes.Add(ParseSize(GetAttributeStringValue(sizeXML, "name"), sizeXML));
            }

            List <ConfigDayInfo> days = new List <ConfigDayInfo>();

            foreach (XmlElement dayInfoXML in GetChildElements(miscConfig["DayInfos"]))
            {
                days.Add(ParseDayInfo(GetAttributeStringValue(dayInfoXML, "name"), dayInfoXML));
            }

            availableConfigs.extraMaterials = ParseExtraMaterials(tilesConfig["ExtraMaterials"]);

            availableConfigs.tileDefinitions   = ParseTileDefinitions(tilesConfig["Tiles"]);
            availableConfigs.itemDefinitions   = ParseItemDefinitions(itemsConfig["Items"]);
            availableConfigs.avatarDefinitions = ParseAvatarDefinitions(avatarsConfig["Avatars"]);

            LoadTileDefinitionsAsItemTileDefinitions();

            ParseTileUpdateRules(tilesConfig["TileRules"]);

            List <ConfigWorldGenerator> generators = new List <ConfigWorldGenerator>();

            foreach (XmlElement generatorXML in GetChildElements(generatorsConfig["Generators"]))
            {
                generators.Add(ParseGenerator(GetAttributeStringValue(generatorXML, "name"), generatorXML));
            }

            availableConfigs.worldGenerators = generators.ToArray();
            availableConfigs.worldSizes      = sizes.ToArray();
            availableConfigs.dayInfos        = days.ToArray();

            return(availableConfigs);
        }
コード例 #2
0
        public AvailableConfigurations Parse(
            string miscConfigTxt,
            string tilesConfigTxt,
            string avatarsConfigTxt,
            string itemsConfigTxt,
            string generatorsConfigTxt)
        {
            availableConfigs = new AvailableConfigurations();

            XmlElement miscConfig = GetConfigXmlElement(miscConfigTxt);
            XmlElement tilesConfig = GetConfigXmlElement(tilesConfigTxt);
            XmlElement avatarsConfig = GetConfigXmlElement(avatarsConfigTxt);
            XmlElement itemsConfig = GetConfigXmlElement(itemsConfigTxt);
            XmlElement generatorsConfig = GetConfigXmlElement(generatorsConfigTxt);

            List<ConfigWorldSize> sizes = new List<ConfigWorldSize>();
            foreach (XmlElement sizeXML in GetChildElements(miscConfig["Sizes"]))
                sizes.Add(ParseSize(GetAttributeStringValue(sizeXML, "name"), sizeXML));

            List<ConfigDayInfo> days = new List<ConfigDayInfo>();
            foreach (XmlElement dayInfoXML in GetChildElements(miscConfig["DayInfos"]))
                days.Add(ParseDayInfo(GetAttributeStringValue(dayInfoXML, "name"), dayInfoXML));

            availableConfigs.extraMaterials = ParseExtraMaterials(tilesConfig["ExtraMaterials"]);

            availableConfigs.tileDefinitions = ParseTileDefinitions(tilesConfig["Tiles"]);
            availableConfigs.itemDefinitions = ParseItemDefinitions(itemsConfig["Items"]);
            availableConfigs.avatarDefinitions = ParseAvatarDefinitions(avatarsConfig["Avatars"]);

            LoadTileDefinitionsAsItemTileDefinitions();

            ParseTileUpdateRules(tilesConfig["TileRules"]);

            List<ConfigWorldGenerator> generators = new List<ConfigWorldGenerator>();
            foreach (XmlElement generatorXML in GetChildElements(generatorsConfig["Generators"]))
                generators.Add(ParseGenerator(GetAttributeStringValue(generatorXML, "name"), generatorXML));

            availableConfigs.worldGenerators = generators.ToArray();
            availableConfigs.worldSizes = sizes.ToArray();
            availableConfigs.dayInfos = days.ToArray();

            return availableConfigs;
        }
コード例 #3
0
ファイル: MainMenu.cs プロジェクト: carriercomm/CubeWorld
    void DrawGenerator()
    {
        if (availableConfigurations == null)
        {
            availableConfigurations = GameManagerUnity.LoadConfiguration();
            currentDayInfoOffset = 0;
            currentGeneratorOffset = 0;
            currentSizeOffset = 0;
            currentGameplayOffset = 0;
        }

        MenuSystem.BeginMenu("Random World Generator");

        MenuSystem.Button("Gameplay: " + GameplayFactory.AvailableGameplays[currentGameplayOffset].name, delegate()
        {
            currentGameplayOffset = (currentGameplayOffset + 1) % GameplayFactory.AvailableGameplays.Length;
        }
        );

        MenuSystem.Button("World Size: " + availableConfigurations.worldSizes[currentSizeOffset].name, delegate()
        {
            currentSizeOffset = (currentSizeOffset + 1) % availableConfigurations.worldSizes.Length;
        }
        );

        MenuSystem.Button("Day Length: " + availableConfigurations.dayInfos[currentDayInfoOffset].name, delegate()
        {
            currentDayInfoOffset = (currentDayInfoOffset + 1) % availableConfigurations.dayInfos.Length;
        }
        );

        if (GameplayFactory.AvailableGameplays[currentGameplayOffset].hasCustomGenerator == false)
        {
            MenuSystem.Button("Generator: " + availableConfigurations.worldGenerators[currentGeneratorOffset].name, delegate()
            {
                currentGeneratorOffset = (currentGeneratorOffset + 1) % availableConfigurations.worldGenerators.Length;
            }
            );
        }

#if !UNITY_WEBPLAYER
        MenuSystem.Button("Host Multiplayer: " + (multiplayer ? "Yes" : "No") , delegate()
        {
            multiplayer = !multiplayer;
        }
        );
#endif

        MenuSystem.LastButton("Generate!", delegate()
        {
            lastConfig = new CubeWorld.Configuration.Config();
            lastConfig.tileDefinitions = availableConfigurations.tileDefinitions;
			lastConfig.itemDefinitions = availableConfigurations.itemDefinitions;
			lastConfig.avatarDefinitions = availableConfigurations.avatarDefinitions;
            lastConfig.dayInfo = availableConfigurations.dayInfos[currentDayInfoOffset];
            lastConfig.worldGenerator = availableConfigurations.worldGenerators[currentGeneratorOffset];
            lastConfig.worldSize = availableConfigurations.worldSizes[currentSizeOffset];
            lastConfig.extraMaterials = availableConfigurations.extraMaterials;
            lastConfig.gameplay = GameplayFactory.AvailableGameplays[currentGameplayOffset];

#if !UNITY_WEBPLAYER
            if (multiplayer)
            {
                MultiplayerServerGameplay multiplayerServerGameplay = new MultiplayerServerGameplay(lastConfig.gameplay.gameplay, true);

                GameplayDefinition g = new GameplayDefinition("", "", multiplayerServerGameplay, false);

                lastConfig.gameplay = g;

                gameManagerUnity.RegisterInWebServer();
            }
#endif

            gameManagerUnity.worldManagerUnity.CreateRandomWorld(lastConfig);

            availableConfigurations = null;

            state = MainMenuState.NORMAL;
        }
        );

        MenuSystem.EndMenu();
    }