Beispiel #1
0
        public void TestInputOutput()
        {
            int width  = 100;
            int height = 1000;

            int[] values  = new int[width * height];
            int[] values2 = new int[width * height];
            values[70]    = 1;
            values[1000]  = 2;
            values[0]     = 3;
            values2[4983] = 1;
            values2[444]  = 2;
            TEnum lenum1 = new TEnum(new string[] { "a", "b", "c", "d" });
            TEnum lenum2 = new TEnum(new string[] { "x", "y", "z" });
            var   map    = new TMap()
            {
                Name           = "test",
                BiomeLayer     = new TMapLayer(width, height, values, lenum1, DefinitionType.Biome),
                ResourceLayers = new TMapLayer[]
                {
                    new TMapLayer(width, height, values2, lenum2, DefinitionType.Resource)
                }
            };

            using (var stream = new MemoryStream())
            {
                MapIO.Export(map, stream, true);
                stream.Seek(0, SeekOrigin.Begin);
                TMap result = MapIO.Import(stream);
                Assert.Equal(map.Name, result.Name);
            }
        }
    private void ImportGUI()
    {
        if (GUI.Button(new Rect(95, 45, 80, 40), "Import map"))
        {
            //get any maps in the folder
            importMapPaths = Directory.GetFiles(MapIO.GetMapFolderPath(), "*.txt");
            numMaps        = importMapPaths.Length;
            importMapNames = new string[numMaps];

            for (int i = 0; i < numMaps; i++)
            {
                importMapNames[i] = Path.GetFileNameWithoutExtension(importMapPaths[i]);
            }
            importActive = !importActive;
        }
        if (importActive)
        {
            scrollPosition = GUI.BeginScrollView(new Rect(95, 90, 150, 60), scrollPosition, new Rect(0, 0, 85 * numMaps, 70));
            for (int i = 0; i < numMaps; i++)
            {
                if (GUI.Button(new Rect(80 * i, 0, 80, 30), importMapNames[i]))
                {
                    controller.ImportMap(importMapPaths[i]);
                    importActive  = false;
                    exportMapName = importMapNames[i];
                }
            }
            GUI.EndScrollView();
        }
    }
Beispiel #3
0
        private static void Main(string[] args)
        {
            Startup.LoadConfiguration();
            var  reader = new PNGMapReader("DefaultMap");
            TMap map    = reader.ReadMap();

            MapIO.Export(map, MapFileProvider.GetMapExportStream());
            Console.WriteLine("Map generated!");
        }
Beispiel #4
0
        public PlayAppState()
        {
            this.camera = new Camera(0, 0, AppSettings.WindowWidth, AppSettings.WindowHeight);
            this.board  = MapIO.LoadMap(MapName);

            this.SetEventResponses();

            this.StartGame();
        }
    public GameObject GetCurrentObject()
    {
        GameObject tile = Resources.Load(MapIO.GetTilePath() + contentToDisplay[selectionGrid].tooltip) as GameObject;

        if (tile == null)
        {
            tile = Resources.Load(MapIO.GetHazardPath() + contentToDisplay[selectionGrid].tooltip) as GameObject;
        }
        return(tile);
    }
Beispiel #6
0
    public void Save(bool useTemp, bool deleteTemp = true)
    {
        if (Data == null)
        {
            Debug.LogError("Tile Map Data is null, cannot save! Invalid loaded map!");
            return;
        }

        // Should be in editor mode for this to work correctly, but it theoretically also works even at runtime.
        string zipFilePath = Data.SavedZipPath;

        Debug.Log("Saving map '{0}' to {1}".Form(this, zipFilePath));

        string fileSaveDir = null;

        if (useTemp)
        {
            // Save to a temporary folder.
            fileSaveDir = Path.Combine(Path.GetTempPath(), Data.InternalName);
        }
        else
        {
            // Save to the extracted (unzipped) folder, and then zip it up anyway.
            fileSaveDir = Path.Combine(GameIO.UnzippedMapsDirectory, Data.InternalName);
        }

        // Save all map data to file.
        Debug.Log("Saving files to '{0}' ({1}) ...".Form(fileSaveDir, useTemp ? "temp" : "pers"));
        GameIO.EnsureDirectory(fileSaveDir);
        var fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_DATA_FILE));

        MapIO.WriteTileIDs(fs, TileIDs);
        MapIO.End(fs);

        // Save metadata.
        GameIO.ObjectToFile(this.Data, Path.Combine(fileSaveDir, METADATA_FILE));

        // Work out all the tile varieties.
        // TODO
        fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_VARIATION_FILE));
        MapIO.WriteTileVariations(fs, this.TileVariations);
        MapIO.End(fs);

        // Grab all the saved files, and zip the up into the save zip path.
        MapIO.Zip(fileSaveDir, zipFilePath);

        // Delete the temporary directory, just to be clean.
        if (useTemp && deleteTemp)
        {
            Directory.Delete(fileSaveDir, true);
        }

        Debug.Log("Finished saving, zipped to '{0}'".Form(zipFilePath));
    }
Beispiel #7
0
        public void OnEnter()
        {
            MapIO.ReadMapsFolder();
            handler = new InputHandler();
            RoomManager.SetRoom("New Test1");
            RoomManager.CurrentRoom.Character = new Character(TexturePool.GetTexture("robot_l"), RoomManager.CurrentRoom, 4, 8);
            StatManager.Stats = new Stat("MrShutCo", 100, 50, 10, 7, 5, 0, 0);
            Camera.Pos        = new Vector2(RoomManager.CurrentRoom.Character.X * 32, RoomManager.CurrentRoom.Character.Y * 32);
            StatViewer CarStat = new StatViewer();

            GUIManager.GUIObjects["stats"] = CarStat;
            handler.RegisterKey(Keys.Back, MenuEnter);
        }
Beispiel #8
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMapService mapService, IStaticDefinitionsService staticDefinitionsService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseMvc();
            using (Stream stream = MapFileProvider.GetMapImportStream())
            {
                mapService.SetMap(MapIO.Import(stream));
            }
            staticDefinitionsService.SetDefinitions(DefinitionsReader.Import());
        }
    private void ExportGUI()
    {
        if (mapExported)
        {
            GUI.Label(new Rect(10, 120, 150, 100), "Map Exported to " + exportMapPath);
        }

        exportMapName = GUI.TextField(new Rect(10, 10, 100, 30), exportMapName);
        if (GUI.Button(new Rect(10, 45, 80, 40), "Export Map"))
        {
            exportMapPath = MapIO.ExportMap(exportMapName, controller.mapParent, controller.propParent);
            if (exportMapPath != null)
            {
                mapExported = true;
            }
        }
    }
Beispiel #10
0
        /// <summary>
        /// マップをロードする
        /// </summary>
        /// <param name="loader">ロードするオブジェクト</param>
        /// <returns>タスク</returns>
        public async Task LoadMapAsync(ILoader loader)
        {
            loader.ProgressInfo = (loader.ProgressInfo.taskCount, 0);

            AddLayer(Map);

            MapIO mapIO = new MapIO();

            mapIO = await BaseIO.LoadAsync <MapIO>(MapPath);

            MapName = mapIO.MapName;

            loader.ProgressInfo = (mapIO.GetMapElementCount(), loader.ProgressInfo.progress);

            await Map.LoadMapData(mapIO, InitDoorID, InitSavePointID, loader);

            foreach (var item in CanUsePlayers)
            {
                Map.AddObject(item);
            }

            Sound.StartBgm(new Sound(mapIO.BGMPath), 2);
        }
    public override void OnInspectorGUI()
    {
        MapIO script = (MapIO)target;

        GUILayout.Label("Load Map", EditorStyles.boldLabel);
        if (GUILayout.Button("Import .map file"))
        {
            loadFile = UnityEditor.EditorUtility.OpenFilePanel("Import Map File", loadFile, "map");

            var blob = new WorldSerialization();
            Debug.Log("Importing map " + loadFile);
            blob.Load(loadFile);
            script.Load(blob);
        }

        GUILayout.Label("Save Map", EditorStyles.boldLabel);
        if (GUILayout.Button("Export .map file"))
        {
            saveFile = UnityEditor.EditorUtility.SaveFilePanel("Export Map File", saveFile, mapName, "map");
            Debug.Log("Exported map " + saveFile);
            script.Save(saveFile);
        }

/*
 *      GUILayout.Label("Select Bundle file", EditorStyles.boldLabel);
 *
 *      bundleFile = GUILayout.TextField(bundleFile);
 *      if (GUILayout.Button("Select Bundle file (Rust\\Bundles\\Bundles)"))
 *      {
 *          bundleFile = UnityEditor.EditorUtility.OpenFilePanel("Select Bundle file (Rust\\Bundles\\Bundles)", bundleFile, "map");
 *      }
 */

        GUILayout.Label("Land Option", EditorStyles.boldLabel);

        GUILayout.Label("Land Heightmap Offset");
        script.offset = float.Parse(GUILayout.TextField(script.offset + ""));
        script.offset = GUILayout.HorizontalSlider(script.offset, -500, 500);
        if (GUILayout.Button("Offset Map"))
        {
            script.offsetHeightmap();
            script.offset = 0;
        }

        string oldLandLayer = script.landLayer;

        string[] options = { "Ground", "Biome", "Alpha", "Topology" };
        script.landSelectIndex = EditorGUILayout.Popup("Select Land Layer:", script.landSelectIndex, options);
        script.landLayer       = options[script.landSelectIndex];
        if (script.landLayer != oldLandLayer)
        {
            script.changeLandLayer();
            Repaint();
        }
        if (script.landLayer.Equals("Topology"))
        {
            GUILayout.Label("Topology Option", EditorStyles.boldLabel);
            script.oldTopologyLayer = script.topologyLayer;
            script.topologyLayer    = (TerrainTopology.Enum)EditorGUILayout.EnumPopup("Select Topology Layer:", script.topologyLayer);
            if (script.topologyLayer != script.oldTopologyLayer)
            {
                //script.saveTopologyLayer();
                script.changeLandLayer();
                Repaint();
            }
        }
    }
    public void ImportMap(string path)
    {
        foreach (Transform child in mapParent)
        {
            table.Remove(child.position);
            child.gameObject.active = false;
            Destroy(child.gameObject);
        }

        mapParent.DetachChildren();

        table.Clear();

        bool result = MapIO.ImportMap(path, mapParent, propParent);

        //if map was successfuly imported, do any post-initialization here
        if (result == true)
        {
            foreach (Transform child in mapParent)
            {
                if (child.name.Contains("Tile"))
                {
                    table.Add(child.position, child.gameObject);
                }
                if (child.name.Contains("MovingTile"))
                {
                    MovingTile importedMovingTile = child.GetComponent <MovingTile>();
                    foreach (Vector3 patrolPoint in importedMovingTile.patrolPoints)
                    {
                        if (!table.Contains(patrolPoint))
                        {
                            MovingTile patrolLoc = Instantiate(importedMovingTile, patrolPoint, Quaternion.identity) as MovingTile;
                            patrolLoc.HalfAlpha();
                            table.Add(patrolPoint, patrolLoc.gameObject);
                        }
                    }
                }
                //If this is a wind hazard
                if (child.name.Contains("Wind"))
                {
                    Vector3 posInMap = child.position;
                    posInMap.y = 0.0f;
                    Tile windTile = (table[posInMap] as GameObject).GetComponent <Tile>();
                    if (windTile != null)
                    {
                        windTile.PlaceObject(child.gameObject);
                    }
                }
            }
            //mark prop containing tiles
            foreach (Transform prop in propParent)
            {
                Vector3 posInMap = prop.position;
                posInMap.y = 0.0f;
                Tile adjacentPropTile = null;
                //check if this prop takes 2 tiles
                if (posInMap.z == (int)posInMap.z)
                {
                    Vector3 adjacentPosInMap = posInMap;
                    posInMap.z         -= 0.5f;
                    adjacentPosInMap.z += 0.5f;
                    adjacentPropTile    = (table[adjacentPosInMap] as GameObject).GetComponent <Tile>();
                }
                else if (posInMap.x == (int)posInMap.x)
                {
                    Vector3 adjacentPosInMap = posInMap;
                    posInMap.x         -= 0.5f;
                    adjacentPosInMap.x += 0.5f;
                    adjacentPropTile    = (table[adjacentPosInMap] as GameObject).GetComponent <Tile>();
                }

                Tile propTile = (table[posInMap] as GameObject).GetComponent <Tile>();
                if (propTile != null)
                {
                    propTile.PlaceObject(prop.gameObject);
                }
                //if this prop takes up more than 2 spaces, add a modifiable component
                if (adjacentPropTile != null)
                {
                    adjacentPropTile.PlaceObject(prop.gameObject);
                    prop.gameObject.AddComponent <ModifiableProp>().SetTiles(propTile, adjacentPropTile);
                }
            }
            tileController.OrganizeTiles();
            FixPropTextures();
        }
    }
Beispiel #13
0
    public void Load(string mapInternalName, bool forceExtract)
    {
        var sw = new System.Diagnostics.Stopwatch();

        sw.Start();

        if (mapInternalName == null)
        {
            Debug.LogError("Map internal name is null, cannot load!");
            return;
        }

        string unzippedPath = GameIO.UnzippedMapsDirectory;

        if (!Directory.Exists(unzippedPath))
        {
            Debug.LogWarning("Unzipped map path ({0}) does not exist, creating it...".Form(unzippedPath));
            Directory.CreateDirectory(unzippedPath);
        }

        string zippedPath     = GameIO.ZippedMapsDirectory;
        string zippedFilePath = Path.Combine(zippedPath, mapInternalName + ".zip");
        bool   zippedExists   = false;

        if (!Directory.Exists(zippedPath))
        {
            Debug.LogWarning("Zipped map path ({0}) does not exist, why? Map will not load unless it has already been unzipped previously.".Form(zippedPath));
        }
        else
        {
            if (File.Exists(zippedFilePath))
            {
                zippedExists = true;
            }
        }

        string destinationUnzippedDirectory = Path.Combine(unzippedPath, mapInternalName);

        if (forceExtract)
        {
            if (!zippedExists)
            {
                Debug.LogError("Extract is required (forced), but map zipped file '{0}' could not be found. Cannot load map!".Form(zippedPath));
                return;
            }

            // Extract the zipped file to the unzipped folder.
            MapIO.UnZip(zippedFilePath, destinationUnzippedDirectory, true);
            Debug.Log("Unzipped map '{0}' to {1}, was forced ({2}).".Form(mapInternalName, destinationUnzippedDirectory, Directory.Exists(destinationUnzippedDirectory) ? "not necessary" : "necessary"));
        }
        else
        {
            // Check to see if an unzipped version exists, otherwise extract...
            if (Directory.Exists(destinationUnzippedDirectory))
            {
                // It does exist! Assume that the files are all correct and loaded properly...
                Debug.Log("Extract not forced, unzipped version of '{0}' found.".Form(mapInternalName));
            }
            else
            {
                // An unzipped version does not exist, extract it!
                if (!zippedExists)
                {
                    Debug.LogError("Extract is required, but map zipped file '{0}' could not be found. Cannot load map!".Form(zippedPath));
                    return;
                }

                // Extract the zipped file to the unzipped folder.
                MapIO.UnZip(zippedFilePath, destinationUnzippedDirectory, true);
                Debug.Log("Unzipped map '{0}' to {1}, was NOT forced (necessary).".Form(mapInternalName, destinationUnzippedDirectory));
            }
        }

        // Now the extracted version should exist.

        // Load map metadata...
        this.Data = GameIO.FileToObject <TileMapData>(Path.Combine(destinationUnzippedDirectory, METADATA_FILE));

        // Load map tile ID data.
        string dataFile = Path.Combine(destinationUnzippedDirectory, TILE_DATA_FILE);
        var    fs       = MapIO.StartRead(dataFile);
        var    data     = MapIO.ReadAllTileIDs(fs, this.Data.SizeInRegions);

        this.TileIDs = null;
        this.TileIDs = data;
        MapIO.End(fs);

        // Load map tile variations...
        string variationFile = Path.Combine(destinationUnzippedDirectory, TILE_VARIATION_FILE);

        fs = MapIO.StartRead(variationFile);
        var varData = MapIO.ReadAllTileVariations(fs, this.Data.SizeInRegions);

        this.TileVariations = null;
        this.TileVariations = varData;
        MapIO.End(fs);

        // Run GC
        Debug.Log("Running GC...");
        Memory.GC();
        Debug.Log("Done!");

        // Done!
        sw.Stop();
        Debug.Log("Done loading map '{0}' in {1} seconds.".Form(mapInternalName, sw.Elapsed.TotalSeconds.ToString("N2")));
    }
Beispiel #14
0
	void Update ()
    {
        prefabData.position = gameObject.transform.position - MapIO.getMapOffset();
        prefabData.rotation = transform.rotation;
        prefabData.scale = transform.localScale;
    }
Beispiel #15
0
        protected override void ExecuteEventResponse(string action, object content)
        {
            base.ExecuteEventResponse(action, content);

            switch (action)
            {
            case "deselect-tool":
                selectedTool = null;
                break;

            case "select-tool":
                selectedTool = (BaseTile)content;
                break;

            case "set-tile":
                SetTile((BaseTile)content);
                break;

            case "add-column":
                board.AddColumn();
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeWidth), board.Width));
                break;

            case "remove-column":
                board.RemoveColumn();
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeWidth), board.Width));
                break;

            case "add-row":
                board.AddRow();
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeHeight), board.Height));
                break;

            case "remove-row":
                board.RemoveRow();
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeHeight), board.Height));
                break;

            case "save-board":
                MapIO.SaveMap(board, mapName);
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.MapSaved), null));
                break;

            case "load-board":
                Board result = MapIO.LoadMap(this.selectedMap);

                this.board   = result;
                this.mapName = board.Name;

                this.camera.Reset();
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.MapLoaded), null));
                break;

            case "change-map-name":
                this.mapName = (string)content;
                break;

            case "reset-board":
                int width  = Int32.Parse(AppSettings.DefaultBoardWidth);
                int height = Int32.Parse(AppSettings.DefaultBoardHeight);

                board = new Board(width, height);
                board.Generate();

                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeHeight), board.Height));
                EventManager.PushEvent(
                    new UIEvent(new EventDetails(this.Name, EventType.ChangeWidth), board.Width));
                break;

            case "scroll-up-file":
                ScrollUpMap();
                break;

            case "scroll-down-file":
                ScrollDownMap();

                break;

            case "select-file":
                this.selectedMap = ((TextboxListItem)content).Text;

                break;
            }
        }