Esempio n. 1
0
        /// <summary>
        /// Draws a given layout and returns a string with SVG data.
        /// </summary>
        /// <param name="layout">Layout that should be drawn</param>
        /// <param name="width">Width of the SVG</param>
        /// <param name="showRoomNames">Whether to show rooms names</param>
        /// <param name="fixedFontSize">What should be the font size of room names</param>
        /// <param name="forceSquare">Whether to force the output to have 1:1 aspect ration</param>
        /// <param name="flipY">Whether to flip ty Y axis</param>
        /// <returns></returns>
        public string DrawLayout(MapLayout <TNode> layout, int width, bool showRoomNames = true, int?fixedFontSize = null, bool forceSquare = false, bool flipY = false)
        {
            if (width <= 0)
            {
                throw new ArgumentException("Width must be greater than zero.", nameof(width));
            }

            var ratio  = GetWidthHeightRatio(layout);
            var height = forceSquare ? width : (int)(width / ratio);

            data.AppendLine($"<svg viewBox=\"0 0 {width} {height}\" xmlns=\"http://www.w3.org/2000/svg\">");

            this.width  = width;
            this.height = height;
            this.flipY  = flipY;

            DrawLayout(layout, width, height, showRoomNames, fixedFontSize, 0.1f);

            data.AppendLine("</svg>");

            var svgData = data.ToString();

            data.Clear();

            return(svgData);
        }
Esempio n. 2
0
        public ActionResult <List <MapLayoutDto> > UpdateMapLayouts(string mainToken, List <MapLayoutDto> dtos)
        {
            var main = _characterService.GetMainCharacterByToken(mainToken);

            if (main == null)
            {
                return(NotFound());
            }
            var dtoIdHash = dtos.Select(x => x.Id).ToHashSet();

            main.MapLayouts.RemoveAll(x => !dtoIdHash.Contains(x.Id));
            foreach (var mapDto in dtos)
            {
                var map = main.MapLayouts.FirstOrDefault(x => x.Id == mapDto.Id);
                if (map == null)
                {
                    map = new MapLayout
                    {
                        Name          = mapDto.Name,
                        SolarSystemId = mapDto.SolarSystemId
                    };
                    main.MapLayouts.Add(map);
                }
                else
                {
                    map.Name          = mapDto.Name;
                    map.SolarSystemId = mapDto.SolarSystemId;
                }
            }
            _characterService.UpdateMainCharacter(main);
            return(Ok(_mapper.Map <List <MapLayoutDto> >(main.MapLayouts)));
        }
Esempio n. 3
0
 public void LoadLevel(MapLayout layout)
 {
     for (int i = 0; i < layout.rooms.Count; ++i)
     {
         Room r = Instantiate <Room>(prefab, map.transform);
         r.SetPostion(layout.rooms[i]);
         r.map = this;
         if (i < layout.events.Count)
         {
             r.SetEvent(layout.events[i]);
         }
         rooms.Add(layout.rooms[i], r);
     }
     foreach (MapUnit u in patrols)
     {
         //placeholder set up
         u.SetPosition(rooms[u.startingPosition]);
         u.SetRoute(new List <Vector2Int>()
         {
             u.waypoint
         });
     }
     units.transform.parent = gameObject.transform;
     units.transform.parent = map.transform;
 }
Esempio n. 4
0
        public static double PositionAndShapeDistance <TNode>(MapLayout <TNode> layout1, MapLayout <TNode> layout2, double differentShapePenalty)
        {
            var nodeToRoomShape1 = layout1.Rooms.Where(x => !x.IsCorridor).ToDictionary(x => x.Node, x => (x.Shape, x.RoomTemplate));
            var nodeToRoomShape2 = layout2.Rooms.Where(x => !x.IsCorridor).ToDictionary(x => x.Node, x => (x.Shape, x.RoomTemplate));

            var differentShapeCounter = 0;

            foreach (var node in nodeToRoomShape1.Keys)
            {
                if (!Equals(nodeToRoomShape1[node].Shape, nodeToRoomShape2[node].Shape) || !Equals(nodeToRoomShape1[node].RoomTemplate, nodeToRoomShape2[node].RoomTemplate))
                {
                    differentShapeCounter++;
                }
            }

            var distance = PositionOnlyDistance(layout1, layout2);

            if (differentShapeCounter / (double)nodeToRoomShape1.Keys.Count > 2 / 3d)
            {
                // distance += (differentShapeCounter - nodeToRoomShape1.Keys.Count / 2) * differentShapePenalty / nodeToRoomShape1.Keys.Count;
                distance = double.MaxValue;
            }

            return(distance);
        }
Esempio n. 5
0
        public static void MakeMaps(Dictionary <string, SpriteSheet> SpriteSheets)
        {
            // Map 1
            int[][] testMapArr =
            {
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
            };

            MapLayout firstLayout = new MapLayout(SpriteSheets["dev"], testMapArr);
            Map       firstMap    = new Map(new List <MapLayout> {
                firstLayout
            });

            // Add all maps
            Maps.Add(firstMap);
        }
Esempio n. 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.MapView);

            MapLayout mapLayout = new MapLayout(this);

            mMapView = mapLayout.MapView;

            //mMapView.SetOpenAPIKeyAuthenticationResultListener(this);
            mMapView.OpenAPIKeyAuthenticationResult += OnOpenAPIKeyAuthenticationResult;
            //mMapView.SetMapViewEventListener(this);
            mMapView.MapViewInitialized      += OnMapViewInitialized;
            mMapView.MapViewCenterPointMoved += OnMapViewCenterPointMoved;
            mMapView.MapViewDoubleTapped     += OnMapViewDoubleTapped;
            mMapView.MapViewLongPressed      += OnMapViewLongPressed;
            mMapView.MapViewSingleTapped     += OnMapViewSingleTapped;
            mMapView.MapViewDragStarted      += OnMapViewDragStarted;
            mMapView.MapViewDragEnded        += OnMapViewDragEnded;
            mMapView.MapViewMoveFinished     += OnMapViewMoveFinished;
            mMapView.MapViewZoomLevelChanged += OnMapViewZoomLevelChanged;
            mMapView.Maptype = MapType.Standard;

            var mapViewContainer = FindViewById <ViewGroup>(Resource.Id.map_view);

            mapViewContainer.AddView(mapLayout);
        }
Esempio n. 7
0
        /// <summary>
        /// Draws a given layout to an output using a given scale and offset.
        /// </summary>
        /// <remarks>
        /// All points are tranfosmer using the TransformPoint method.
        /// </remarks>
        /// <param name="layout">Layout do be drawn</param>
        /// <param name="scale">Scale factor</param>
        /// <param name="offset"></param>
        /// <param name="withNames">Whether names should be displayed</param>
        /// <param name="fixedFontSize"></param>
        protected void DrawLayout(MapLayout <TNode> layout, float scale, Vector2Int offset, bool withNames, int?fixedFontSize = null)
        {
            var polygons = layout.Rooms.Select(x => x.Shape + x.Position).ToList();
            var rooms    = layout.Rooms.ToList();
            var minWidth = layout.Rooms.Where(x => !x.IsCorridor).Select(x => x.Shape + x.Position).Min(x => x.BoundingRectangle.Width);

            for (var i = 0; i < rooms.Count; i++)
            {
                var room    = rooms[i];
                var outline = GetOutline(polygons[i], room.Doors?.ToList())
                              .Select(x => Tuple.Create(TransformPoint(x.Item1, scale, offset), x.Item2)).ToList();

                var transformedPoints = polygons[i].GetPoints().Select(point => TransformPoint(point, scale, offset)).ToList();

                if (transformedPoints.All(x => x == new Vector2Int(0, 0)))
                {
                    throw new InvalidOperationException("One of the polygons could not be drawn because the canvas size is too small.");
                }

                var polygon = new PolygonGrid2D(transformedPoints);
                DrawRoom(polygon, outline, 2);

                if (withNames && !room.IsCorridor)
                {
                    DrawTextOntoPolygon(polygon, room.Node.ToString(), fixedFontSize ?? 2.5f * minWidth);
                }
            }
        }
Esempio n. 8
0
 public void OnEditCurrentButtonPressed()
 {
     // Commit what's currently on screen to the editor layout, and then edit that.
     m_editLayout    = m_visibleLayout.Duplicate();
     m_layoutChanged = true;
     SwitchMode(EditorMode.Edit);
 }     // OnEditCurrentButtonPressed
Esempio n. 9
0
        private void automaticSlideshowCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            if (automaticSlideshowCheckbox.Checked)
            {
                var id = ++slideshowTaskId;

                Task.Run(() =>
                {
                    for (var i = slideshowIndex; i < generatedLayouts.Count; i++)
                    {
                        if (slideshowTaskId != id || !automaticSlideshowCheckbox.Checked)
                        {
                            return;
                        }

                        var idToShow = i;

                        Invoke((Action)(() =>
                        {
                            slideshowIndex = idToShow;
                            UpdateSlideshowInfo();
                            layoutToDraw = generatedLayouts[idToShow];
                            mainPictureBox.Refresh();
                        }));

                        Thread.Sleep(3000);
                    }
                });
            }
        }
    public static Loadzone FindLoadzoneToSpawnAt(string sceneEnteredFrom, string currentSceneName)
    {
        var      zones = GameObject.FindObjectsOfType <Loadzone>();
        Loadzone loadZoneSpecifying = null;

        foreach (Loadzone zone in zones)
        {
            if (zone.loadSpecifiedRoomInsteadOfCardinal)
            {
                if (sceneEnteredFrom == zone.SceneToLoad)
                {
                    loadZoneSpecifying = zone;
                }
            }
            else
            {
                string rnt = MapLayout.GetRoomNextTo(currentSceneName, zone.whichSideOfRoom);
                if (sceneEnteredFrom == rnt)
                {
                    //GetOppositeCardinal(zone.whichSideOfRoom)) {
                    return(zone);
                }
            }
        }
        return(loadZoneSpecifying);
    }
        public GameInstance(String name, MapLayout mapLayout)
            : base("Instance-" + name)
        {
            this.name = name;
            this.map  = new GameMap(mapLayout);

            Log.MessageLogged += Console.WriteLine;
        }
Esempio n. 12
0
        public BoardRenderer()
        {
            _display = new Display();

            _sprites    = new Sprites();
            _scoreBoard = new ScoreBoard(_display, _sprites);
            _mapLayout  = new MapLayout();
        }
Esempio n. 13
0
        /// <summary>
        /// Serializes a given layout to JSON.
        /// </summary>
        /// <param name="layout"></param>
        /// <param name="writer"></param>
        public void Serialize(MapLayout <TNode> layout, StreamWriter writer)
        {
            var json = JsonConvert.SerializeObject(
                layout.Rooms.Select(x => modelConverter.GetRoomModel(x)),
                Formatting.Indented
                );

            writer.Write(json);
        }
Esempio n. 14
0
    }     // FloodFillSingleArea_Recursive

    public MapLayout Duplicate()
    {
        MapLayout clone = new MapLayout();

        clone.Colours       = (int[])Colours.Clone();
        clone.AreaIDs       = (int[])AreaIDs.Clone();
        clone.TilesForAreas = new List <int>(TilesForAreas);
        return(clone);
    }     // Duplicate
    public Rect VisibleRect(Camera camera)
    {
        VisibleArea va = MapLayout.CalcRelativeVisibleArea(camera);

        return(new Rect(camera.transform.localPosition.x - va.farHalfWidth,
                        camera.transform.localPosition.z + va.near,
                        va.farHalfWidth * 2f,
                        va.far - va.near));
    }
Esempio n. 16
0
        private void mainPictureBox_Paint(object sender, PaintEventArgs e)
        {
            if (layoutToDraw == null)
            {
                return;
            }

            if (exportShownLayoutsCheckbox.Checked)
            {
                DumpSvg();
            }

            UpdateLayoutType();

            var showNames        = showRoomNamesCheckbox.Checked;
            var useOldPaperStyle = useOldPaperStyleCheckbox.Checked;
            var fixedFontSize    = fixedFontSizeCheckbox.Checked ? (int?)fixedFontSizeValue.Value : null;

            if (firstChainToDraw == null)
            {
                firstChainToDraw = layoutToDraw;
                RecomputeFixedScaleAndOffset();
            }
            else
            {
                var previousRoomsCount = firstChainToDraw.Rooms.Count();
                var currentRoomsCount  = layoutToDraw.Rooms.Count();

                if (previousRoomsCount == currentRoomsCount)
                {
                    firstChainToDraw = layoutToDraw;
                    RecomputeFixedScaleAndOffset();
                }
            }

            if (useOldPaperStyle)
            {
                var bitmap = oldMapDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize);
                e.Graphics.DrawImage(bitmap, new Point(0, 0));
            }
            else
            {
                Bitmap bitmap;

                if (fixedPositionsAndScaleCheckbox.Checked)
                {
                    bitmap = wfLayoutDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize, fixedScale, fixedOffset);
                }
                else
                {
                    bitmap = wfLayoutDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize);
                }

                e.Graphics.DrawImage(bitmap, new Point(0, 0));
            }
        }
Esempio n. 17
0
    private void Start()
    {
        Instance = this;

        layout = new MapLayout();
        layout.Init(roomSize.x, roomSize.y);
        layout.GenerateLayout();

        SpawningRoom();
    }
Esempio n. 18
0
    }     // SwitchMode

    private void UpdateMapVisuals(MapLayout _layout, bool _highlightRemovedTiles)
    {
        for (int y = 0; y < Constants.EditableHeight; ++y)
        {
            for (int x = 0; x < Constants.EditableWidth; ++x)
            {
                UpdateTileVisuals(x, y, _layout.GetColour(x, y), _highlightRemovedTiles);
            }
        }
    }     // UpdateMapVisuals
        public GameInstance(String name, MapLayout mapLayout)
        {
            this.Name = name;
            this.map  = new GameMap(mapLayout);

            this.Log = new DebugLogger("Inst:" + name);
            this.Log.MessageLogged += Console.WriteLine;

            gameTime.Start();
            Log.Log("Started.");
        }
Esempio n. 20
0
    public static MapLayout BossLayout()
    {
        var layout = new MapLayout();
        layout.spawns.Add(new Spawn(new MapPosition(1, 0, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(0, 1, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(0, 2, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(2, 3, Const.Team.Player), Character.Fighter()));

        layout.spawns.Add(new Spawn(new MapPosition(1, 1, Const.Team.Enemy), Character.SlimeKing()));
        return layout;
    }
Esempio n. 21
0
        private void slideshowRightButton_Click(object sender, EventArgs e)
        {
            automaticSlideshowCheckbox.Checked = false;

            if (slideshowIndex != generatedLayouts.Count - 1)
            {
                layoutToDraw = generatedLayouts[++slideshowIndex];
                mainPictureBox.Refresh();
            }

            UpdateSlideshowInfo();
        }
Esempio n. 22
0
    public Vector2 ObjectPositionAtMapPoint(MapPoint mapPoint)
    {
        Vector2 worldPosition = MapLayout.ScreenPointFromMapPoint(mapPoint);
        Tile    tile          = TileAtMapPoint(mapPoint);

        Debug.Log("Tile centre :" + tile.centreX + "," + tile.centreY);

        worldPosition.x += (tile.centreX / 100.0f) - 0.5f;
        worldPosition.y += (tile.centreY / 100.0f);

        return(worldPosition);
    }
Esempio n. 23
0
        /**
         * Send the map layout request message through the socket to the server
         * @param Message the message to send
         */
        private void RequestMapLayout(String Message)
        {
            MapLayout request = new MapLayout();

            request.mapInfo = Message;
            MemoryStream outStream = request.WriteData(Salt);

            try
            {
                clientSocket.Send(outStream.GetBuffer());
            }
            catch { }
        }
Esempio n. 24
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            parent.DestroyChildrens();
            parent.localScale = Vector3.one;

            layout = new MapLayout();
            layout.Init(roomSize.x, roomSize.y);
            layout.GenerateLayout();

            SpawningRoom();
        }
    }
Esempio n. 25
0
        private float GetWidthHeightRatio(MapLayout <TNode> layout)
        {
            var polygons = layout.Rooms.Select(x => x.Shape + x.Position).ToList();
            var points   = polygons.SelectMany(x => x.GetPoints()).ToList();

            var minx = points.Min(x => x.X);
            var miny = points.Min(x => x.Y);
            var maxx = points.Max(x => x.X);
            var maxy = points.Max(x => x.Y);

            var ratio = (maxx - minx) / (float)(maxy - miny);

            return(ratio);
        }
Esempio n. 26
0
    public static MapLayout GetDefaultLayout()
    {
        var layout = new MapLayout();
        layout.spawns.Add(new Spawn(new MapPosition(1, 0, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 1, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 2, Const.Team.Player), Character.Fighter()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 3, Const.Team.Player), Character.Fighter()));

        layout.spawns.Add(new Spawn(new MapPosition(1, 0, Const.Team.Enemy), Character.Slime()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 1, Const.Team.Enemy), Character.Slime()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 2, Const.Team.Enemy), Character.Slime()));
        layout.spawns.Add(new Spawn(new MapPosition(1, 3, Const.Team.Enemy), Character.Slime()));
        return layout;
    }
Esempio n. 27
0
        private void ChangeCurrentMap(MapLayout map)
        {
            // Don't change the map if it isn't different
            if (_currentMap == map)
            {
                return;
            }

            // Change and set a new map
            _mapGraphics.SetMap(map.MapImage);
            _mapGraphics.SetBackground(map.BackgroundImage);

            _currentMap = map;
        }
Esempio n. 28
0
        private void ChangeCurrentMap(MapLayout map)
        {
            // Don't change the map if it isn't different
            if (_currentMap == map)
            {
                return;
            }

            _layout.ChangeImage(map.MapImage);
            _currentMap = map;

            _layout.Region = map.Coordinates;
            _layout.Y      = map.Y != float.MinValue ? map.Y : 0.0f;
        }
    public void SaveToAssets()
    {
        if (MapName == "")
        {
            Debug.Log("Must Instantiate Name");
            return;
        }
        MapLayout layout = new MapLayout();

        foreach (Vector2Int coord in coords.Keys)
        {
            layout.rooms.Add(coord);
        }
        AssetDatabase.CreateAsset(layout, "Assets/Scriptable_Objects/Map/" + MapName + ".asset");
    }
Esempio n. 30
0
        /// <summary>
        /// Entry point of the class. Draws a given layout to an output with given dimensions.
        /// </summary>
        /// <param name="layout">Layout do be drawn</param>
        /// <param name="width">Width of the output</param>
        /// <param name="height">Height of the output</param>
        /// <param name="withNames">Whether names should be displayed</param>
        /// <param name="fixedFontSize"></param>
        /// <param name="borderSize"></param>
        protected void DrawLayout(MapLayout <TNode> layout, int width, int height, bool withNames, int?fixedFontSize = null, float borderSize = 0.2f)
        {
            var polygons = layout.Rooms.Select(x => x.Shape + x.Position).ToList();
            var points   = polygons.SelectMany(x => x.GetPoints()).ToList();

            var minx = points.Min(x => x.X);
            var miny = points.Min(x => x.Y);
            var maxx = points.Max(x => x.X);
            var maxy = points.Max(x => x.Y);

            var scale  = GetScale(minx, miny, maxx, maxy, width, height, borderSize);
            var offset = GetOffset(minx, miny, maxx, maxy, width, height, scale);

            DrawLayout(layout, scale, offset, withNames, fixedFontSize);
        }
Esempio n. 31
0
    public void HandleClick(Vector3 mousePosition)
    {
        Vector3 mapPosition     = mousePosition - transform.position;
        Vector2 mousePosition2D = new Vector2(mapPosition.x, mapPosition.y);

        MapPoint            destinationPoint = MapLayout.MapPointFromWorldPoint(mousePosition2D);
        List <MovementStep> progression      = controller.map.GeneratePath(playerPersonController.CurrentPosition, destinationPoint);

        if (progression == null)
        {
            Debug.LogError("No path to " + destinationPoint);
            return;
        }

        playerPersonController.MoveAlongPath(progression, null);
    }
Esempio n. 32
0
        private void UpdateMap()
        {
            LevelDataModel level     = DataModels.Level;
            float          marioRelY = DataModels.Mario.PURelative_Y;
            MapLayout      bestMap   = Config.MapAssociations.GetBestMap(
                level.Index, level.Area, level.LoadingPoint, level.MissionLayout, marioRelY);

            object mapLayoutChoice = Config.MapGui.ComboBoxLevel.SelectedItem;

            if (mapLayoutChoice is MapLayout)
            {
                bestMap = (MapLayout)mapLayoutChoice;
            }

            ChangeCurrentMap(bestMap);
        }