| 2341 | } |
| 2342 | |
| 2343 | func (mapData *MapData) Rotate(counterClockwise bool) { |
| 2344 | |
| 2345 | oldData := [][]int{} |
| 2346 | |
| 2347 | for y := range mapData.Data { |
| 2348 | if y >= mapData.Height { |
| 2349 | break |
| 2350 | } |
| 2351 | oldData = append(oldData, []int{}) |
| 2352 | for x := range mapData.Data[y] { |
| 2353 | if x >= mapData.Width { |
| 2354 | break |
| 2355 | } |
| 2356 | oldData[y] = append(oldData[y], mapData.Data[y][x]) |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | newWidth := float32(mapData.Height) * globals.GridSize |
| 2361 | newHeight := float32(mapData.Width) * globals.GridSize |
| 2362 | |
| 2363 | mapData.Contents.Card.Recreate(newWidth, newHeight) |
| 2364 | |
| 2365 | mapData.Data = [][]int{} |
| 2366 | mapData.Resize(int(newWidth/globals.GridSize), int(newHeight/globals.GridSize)) |
| 2367 | |
| 2368 | for y := range oldData { |
| 2369 | for x := range oldData[y] { |
| 2370 | if counterClockwise { |
| 2371 | invY := len(oldData) - 1 - y |
| 2372 | mapData.Data[x][invY] = oldData[y][x] |
| 2373 | } else { |
| 2374 | invX := len(oldData[y]) - 1 - x |
| 2375 | mapData.Data[invX][y] = oldData[y][x] |
| 2376 | } |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | mapData.Contents.UpdateTexture() |
| 2381 | |
| 2382 | contents := mapData.Contents.Card.Properties.Get("contents") |
| 2383 | contents.SetRaw(mapData.Serialize()) |
| 2384 | |
| 2385 | mapData.Contents.Card.CreateUndoState = true |
| 2386 | |
| 2387 | if counterClockwise { |
| 2388 | globals.EventLog.Log("Map rotated 90 degrees counter-clockwise.", false) |
| 2389 | } else { |
| 2390 | globals.EventLog.Log("Map rotated 90 degrees clockwise.", false) |
| 2391 | } |
| 2392 | |
| 2393 | } |
| 2394 | |
| 2395 | func (mapData *MapData) Flip(vertical bool) { |
| 2396 | |