MCPcopy Create free account
hub / github.com/SolarLune/masterplan / Rotate

Method Rotate

contents.go:2343–2393  ·  view source on GitHub ↗
(counterClockwise bool)

Source from the content-addressed store, hash-verified

2341}
2342
2343func (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
2395func (mapData *MapData) Flip(vertical bool) {
2396

Callers 1

UpdateMethod · 0.45

Calls 7

ResizeMethod · 0.95
SerializeMethod · 0.95
SetRawMethod · 0.80
LogMethod · 0.80
RecreateMethod · 0.45
UpdateTextureMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected