2020-06-13 20:36:20 -04:00
|
|
|
package d2gamescreen
|
2019-10-27 19:00:38 -04:00
|
|
|
|
|
|
|
import (
|
2020-07-02 13:55:43 -04:00
|
|
|
"fmt"
|
2020-06-23 01:05:01 -04:00
|
|
|
"log"
|
2019-11-15 09:04:27 -05:00
|
|
|
"os"
|
2020-06-19 02:19:27 -04:00
|
|
|
"time"
|
2019-11-06 18:25:19 -05:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapgen"
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer"
|
2020-02-02 14:59:47 -05:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-06-28 21:40:52 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-06-13 20:36:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
|
2019-10-27 19:00:38 -04:00
|
|
|
)
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
type regionSpec struct {
|
2019-11-17 00:52:13 -05:00
|
|
|
regionType d2enum.RegionIdType
|
|
|
|
startPresetIndex int
|
|
|
|
endPresetIndex int
|
|
|
|
extra []int
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
var regions = []regionSpec{
|
|
|
|
// Act I
|
2019-11-17 00:52:13 -05:00
|
|
|
{d2enum.RegionAct1Town, 1, 3, []int{}},
|
|
|
|
{d2enum.RegionAct1Wilderness, 4, 52, []int{
|
|
|
|
108,
|
|
|
|
160, 161, 162, 163, 164,
|
|
|
|
}},
|
|
|
|
{d2enum.RegionAct1Cave, 53, 107, []int{}},
|
|
|
|
{d2enum.RegionAct1Crypt, 109, 159, []int{}},
|
|
|
|
{d2enum.RegionAct1Monestary, 165, 165, []int{}},
|
|
|
|
{d2enum.RegionAct1Courtyard, 166, 166, []int{256}},
|
|
|
|
{d2enum.RegionAct1Barracks, 167, 205, []int{}},
|
|
|
|
{d2enum.RegionAct1Jail, 206, 255, []int{}},
|
|
|
|
{d2enum.RegionAct1Cathedral, 257, 257, []int{}},
|
|
|
|
{d2enum.RegionAct1Catacombs, 258, 299, []int{}},
|
|
|
|
{d2enum.RegionAct1Tristram, 300, 300, []int{}},
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Act II
|
2019-11-17 00:52:13 -05:00
|
|
|
{d2enum.RegionAct2Town, 301, 301, []int{}},
|
|
|
|
{d2enum.RegionAct2Sewer, 302, 352, []int{}},
|
|
|
|
{d2enum.RegionAct2Harem, 353, 357, []int{}},
|
|
|
|
{d2enum.RegionAct2Basement, 358, 361, []int{}},
|
|
|
|
{d2enum.RegionAct2Desert, 362, 413, []int{}},
|
|
|
|
{d2enum.RegionAct2Tomb, 414, 481, []int{}},
|
|
|
|
{d2enum.RegionAct2Lair, 482, 509, []int{}},
|
|
|
|
{d2enum.RegionAct2Arcane, 510, 528, []int{}},
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Act III
|
2019-11-17 00:52:13 -05:00
|
|
|
{d2enum.RegionAct3Town, 529, 529, []int{}},
|
|
|
|
{d2enum.RegionAct3Jungle, 530, 604, []int{}},
|
|
|
|
{d2enum.RegionAct3Kurast, 605, 658, []int{
|
2020-07-02 13:55:43 -04:00
|
|
|
748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769,
|
|
|
|
770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791,
|
|
|
|
792, 793, 794, 795, 796,
|
2019-11-17 00:52:13 -05:00
|
|
|
}},
|
|
|
|
{d2enum.RegionAct3Spider, 659, 664, []int{}},
|
|
|
|
{d2enum.RegionAct3Dungeon, 665, 704, []int{}},
|
|
|
|
{d2enum.RegionAct3Sewer, 705, 747, []int{}},
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Act IV
|
2019-11-17 00:52:13 -05:00
|
|
|
{d2enum.RegionAct4Town, 797, 798, []int{}},
|
|
|
|
{d2enum.RegionAct4Mesa, 799, 835, []int{}},
|
|
|
|
{d2enum.RegionAct4Lava, 836, 862, []int{}},
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Act V -- broken or wrong order
|
2019-11-17 00:52:13 -05:00
|
|
|
{d2enum.RegonAct5Town, 863, 864, []int{}},
|
|
|
|
{d2enum.RegionAct5Siege, 865, 879, []int{}},
|
|
|
|
{d2enum.RegionAct5Barricade, 880, 1002, []int{}},
|
|
|
|
{d2enum.RegionAct5IceCaves, 1003, 1041, []int{}},
|
|
|
|
{d2enum.RegionAct5Temple, 1042, 1052, []int{}},
|
|
|
|
{d2enum.RegionAct5Baal, 1059, 1090, []int{}},
|
|
|
|
{d2enum.RegionAct5Lava, 1053, 1058, []int{}},
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
// MapEngineTest represents the MapEngineTest screen
|
2019-10-27 19:00:38 -04:00
|
|
|
type MapEngineTest struct {
|
2020-07-13 20:29:17 -04:00
|
|
|
gameState *d2player.PlayerState
|
|
|
|
mapEngine *d2mapengine.MapEngine
|
|
|
|
mapRenderer *d2maprenderer.MapRenderer
|
|
|
|
terminal d2interface.Terminal
|
|
|
|
renderer d2interface.Renderer
|
|
|
|
inputManager d2interface.InputManager
|
2019-11-17 00:52:13 -05:00
|
|
|
|
|
|
|
//TODO: this is region specific properties, should be refactored for multi-region rendering
|
2019-11-13 14:26:42 -05:00
|
|
|
currentRegion int
|
2019-11-17 00:52:13 -05:00
|
|
|
levelPreset int
|
|
|
|
fileIndex int
|
2020-07-02 13:55:43 -04:00
|
|
|
regionSpec regionSpec
|
2019-11-17 00:52:13 -05:00
|
|
|
filesCount int
|
2019-12-13 00:33:11 -05:00
|
|
|
debugVisLevel int
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// CreateMapEngineTest creates the Map Engine Test screen and returns a pointer to it
|
2020-07-13 20:29:17 -04:00
|
|
|
func CreateMapEngineTest(currentRegion, levelPreset int, term d2interface.Terminal, renderer d2interface.Renderer, inputManager d2interface.InputManager) *MapEngineTest {
|
2019-10-27 19:00:38 -04:00
|
|
|
result := &MapEngineTest{
|
2019-11-13 14:26:42 -05:00
|
|
|
currentRegion: currentRegion,
|
2019-11-17 00:52:13 -05:00
|
|
|
levelPreset: levelPreset,
|
2019-11-17 08:09:54 -05:00
|
|
|
fileIndex: 0,
|
2020-07-02 13:55:43 -04:00
|
|
|
regionSpec: regionSpec{},
|
2019-11-17 00:52:13 -05:00
|
|
|
filesCount: 0,
|
2020-06-28 21:40:52 -04:00
|
|
|
terminal: term,
|
2020-07-03 14:00:56 -04:00
|
|
|
renderer: renderer,
|
2020-07-13 20:29:17 -04:00
|
|
|
inputManager: inputManager,
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
result.gameState = d2player.CreateTestGameState()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-10-27 19:00:38 -04:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
func (met *MapEngineTest) loadRegionByIndex(n, levelPreset, fileIndex int) {
|
2020-06-23 01:05:01 -04:00
|
|
|
log.Printf("Loaded region: Type(%d) LevelPreset(%d) FileIndex(%d)", n, levelPreset, fileIndex)
|
2020-06-21 18:40:37 -04:00
|
|
|
d2maprenderer.InvalidateImageCache()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
for _, spec := range regions {
|
2020-07-06 20:13:55 -04:00
|
|
|
if spec.regionType != d2enum.RegionIdType(n) {
|
|
|
|
continue
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
met.regionSpec = spec
|
|
|
|
inExtra := false
|
|
|
|
|
|
|
|
for _, e := range spec.extra {
|
|
|
|
if e == levelPreset {
|
|
|
|
inExtra = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 14:26:42 -05:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
if !inExtra {
|
|
|
|
if levelPreset < spec.startPresetIndex {
|
|
|
|
levelPreset = spec.startPresetIndex
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
if levelPreset > spec.endPresetIndex {
|
|
|
|
levelPreset = spec.endPresetIndex
|
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2020-07-06 20:13:55 -04:00
|
|
|
|
|
|
|
met.levelPreset = levelPreset
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2019-11-13 14:26:42 -05:00
|
|
|
|
|
|
|
if n == 0 {
|
2020-06-21 23:23:00 -04:00
|
|
|
met.mapEngine.SetSeed(time.Now().UnixNano())
|
2020-06-21 18:40:37 -04:00
|
|
|
d2mapgen.GenerateAct1Overworld(met.mapEngine)
|
2019-11-17 16:06:02 -05:00
|
|
|
} else {
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapEngine = d2mapengine.CreateMapEngine() // necessary for map name update
|
2020-06-21 23:23:00 -04:00
|
|
|
met.mapEngine.SetSeed(time.Now().UnixNano())
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapEngine.GenerateMap(d2enum.RegionIdType(n), levelPreset, fileIndex, true)
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapEngine.RegenerateWalkPaths()
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapRenderer.SetMapEngine(met.mapEngine)
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.MoveCameraTo(met.mapRenderer.WorldToOrtho(met.mapEngine.GetCenterPosition()))
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnLoad loads the resources for the Map Engine Test screen
|
2020-06-24 18:46:03 -04:00
|
|
|
func (met *MapEngineTest) OnLoad(loading d2screen.LoadingState) {
|
2020-07-13 20:29:17 -04:00
|
|
|
if err := met.inputManager.BindHandler(met); err != nil {
|
2020-07-02 13:55:43 -04:00
|
|
|
fmt.Printf("could not add MapEngineTest as event handler")
|
|
|
|
}
|
|
|
|
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.2)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapEngine = d2mapengine.CreateMapEngine()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.5)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
met.mapRenderer = d2maprenderer.CreateMapRenderer(met.renderer, met.mapEngine, met.terminal)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.7)
|
2020-07-02 13:55:43 -04:00
|
|
|
met.loadRegionByIndex(met.currentRegion, met.levelPreset, met.fileIndex)
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnUnload releases the resources for the Map Engine Test screen
|
2020-02-08 21:02:37 -05:00
|
|
|
func (met *MapEngineTest) OnUnload() error {
|
2020-07-13 20:29:17 -04:00
|
|
|
if err := met.inputManager.UnbindHandler(met); err != nil {
|
2020-07-02 13:55:43 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Render renders the Map Engine Test screen
|
2020-06-29 00:41:58 -04:00
|
|
|
func (met *MapEngineTest) Render(screen d2interface.Surface) error {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.Render(screen)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
// levelFilesToPick := make([]string, 0)
|
|
|
|
// fileIndex := met.fileIndex
|
|
|
|
// levelPreset := curRegion.LevelPreset()
|
|
|
|
// regionPath := curRegion.RegionPath()
|
|
|
|
// for n, fileRecord := range levelPreset.Files {
|
|
|
|
// if len(fileRecord) == 0 || fileRecord == "" || fileRecord == "0" {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// levelFilesToPick = append(levelFilesToPick, fileRecord)
|
|
|
|
// if fileRecord == regionPath {
|
|
|
|
// fileIndex = n
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if met.fileIndex == -1 {
|
|
|
|
// met.fileIndex = fileIndex
|
|
|
|
// }
|
|
|
|
// met.filesCount = len(levelFilesToPick)
|
2020-06-21 18:40:37 -04:00
|
|
|
//
|
|
|
|
//
|
2020-07-06 20:13:55 -04:00
|
|
|
// regionWidth, regionHeight := curRegion.GetTileSize()
|
|
|
|
// if tileX >= 0 && tileY >= 0 && tileX < regionWidth && tileY < regionHeight {
|
|
|
|
// tile := curRegion.Tile(tileX, tileY)
|
|
|
|
// screen.PushTranslation(5, 5)
|
|
|
|
// screen.DrawText("%d, %d (Tile %d.%d, %d.%d)", screenX, screenY, tileX, subtileX, tileY, subtileY)
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Map: " + curRegion.LevelType().Name)
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("%v: %v/%v [%v, %v]", regionPath, fileIndex+1, met.filesCount, met.currentRegion, met.levelPreset)
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("N - next region, P - previous region")
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Shift+N - next preset, Shift+P - previous preset")
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Ctrl+N - next file, Ctrl+P - previous file")
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// popN := 7
|
|
|
|
// if len(tile.Floors) > 0 {
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Floors:")
|
|
|
|
// screen.PushTranslation(16, 0)
|
|
|
|
// for idx, floor := range tile.Floors {
|
|
|
|
// popN++
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// tileData := curRegion.TileData(int32(floor.Style), int32(floor.Sequence), d2enum.Floor)
|
|
|
|
// tileSubAttrs := d2dt1.SubTileFlags{}
|
|
|
|
// if tileData != nil {
|
|
|
|
// tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
|
|
|
// }
|
|
|
|
// screen.DrawText("Floor %v: [ANI:%t] %s", idx, floor.Animated, tileSubAttrs.DebugString())
|
2020-06-21 18:40:37 -04:00
|
|
|
//
|
2020-07-06 20:13:55 -04:00
|
|
|
// }
|
|
|
|
// screen.PushTranslation(-16, 0)
|
|
|
|
// popN += 3
|
|
|
|
// }
|
|
|
|
// if len(tile.Walls) > 0 {
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Walls:")
|
|
|
|
// screen.PushTranslation(16, 0)
|
|
|
|
// for idx, wall := range tile.Walls {
|
|
|
|
// popN++
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// tileData := curRegion.TileData(int32(wall.Style), int32(wall.Sequence), d2enum.Floor)
|
|
|
|
// tileSubAttrs := d2dt1.SubTileFlags{}
|
|
|
|
// if tileData != nil {
|
|
|
|
// tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
|
|
|
// }
|
|
|
|
// screen.DrawText("Wall %v: [HID:%t] %s", idx, wall.Hidden, tileSubAttrs.DebugString())
|
2020-06-21 18:40:37 -04:00
|
|
|
//
|
2020-07-06 20:13:55 -04:00
|
|
|
// }
|
|
|
|
// screen.PushTranslation(-16, 0)
|
|
|
|
// popN += 3
|
|
|
|
// }
|
|
|
|
// if len(tile.Walls) > 0 {
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// screen.DrawText("Shadows:")
|
|
|
|
// screen.PushTranslation(16, 0)
|
|
|
|
// for idx, shadow := range tile.Shadows {
|
|
|
|
// popN++
|
|
|
|
// screen.PushTranslation(0, 16)
|
|
|
|
// tileData := curRegion.TileData(int32(shadow.Style), int32(shadow.Sequence), d2enum.Floor)
|
|
|
|
// tileSubAttrs := d2dt1.SubTileFlags{}
|
|
|
|
// if tileData != nil {
|
|
|
|
// tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
|
|
|
// }
|
|
|
|
// screen.DrawText("Wall %v: [HID:%t] %s", idx, shadow.Hidden, tileSubAttrs.DebugString())
|
2020-06-21 18:40:37 -04:00
|
|
|
//
|
2020-07-06 20:13:55 -04:00
|
|
|
// }
|
|
|
|
// screen.PushTranslation(-16, 0)
|
|
|
|
// popN += 3
|
|
|
|
// }
|
|
|
|
// screen.PopN(popN)
|
|
|
|
// }
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
return nil
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Advance runs the update logic on the Map Engine Test screen
|
2020-02-08 21:02:37 -05:00
|
|
|
func (met *MapEngineTest) Advance(tickTime float64) error {
|
2020-02-01 21:51:49 -05:00
|
|
|
met.mapEngine.Advance(tickTime)
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapRenderer.Advance(tickTime)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnKeyRepeat is called to handle repeated key presses
|
2020-07-03 15:09:16 -04:00
|
|
|
func (met *MapEngineTest) OnKeyRepeat(event d2interface.KeyEvent) bool {
|
2020-01-25 23:28:21 -05:00
|
|
|
var moveSpeed float64 = 8
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.KeyMod() == d2enum.KeyModShift {
|
2020-01-25 23:28:21 -05:00
|
|
|
moveSpeed *= 2
|
2019-12-08 22:18:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyDown {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.MoveCameraBy(0, moveSpeed)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-01 14:12:23 -04:00
|
|
|
}
|
2020-01-25 23:28:21 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyUp {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.MoveCameraBy(0, -moveSpeed)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-01 14:12:23 -04:00
|
|
|
}
|
2019-11-15 09:04:27 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyRight {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.MoveCameraBy(moveSpeed, 0)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyLeft {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.MoveCameraBy(-moveSpeed, 0)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-15 09:04:27 -05:00
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnKeyDown defines the actions of the Map Engine Test screen when a key is pressed
|
2020-07-03 15:09:16 -04:00
|
|
|
func (met *MapEngineTest) OnKeyDown(event d2interface.KeyEvent) bool {
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyEscape {
|
2019-11-13 14:26:42 -05:00
|
|
|
os.Exit(0)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyN {
|
2020-07-03 15:09:16 -04:00
|
|
|
switch event.KeyMod() {
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModControl:
|
2020-06-23 01:05:01 -04:00
|
|
|
met.fileIndex++
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModShift:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.levelPreset = increment(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-07-02 13:55:43 -04:00
|
|
|
default:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.currentRegion = increment(met.currentRegion, 0, len(regions))
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-17 08:09:54 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyP {
|
2020-07-03 15:09:16 -04:00
|
|
|
switch event.KeyMod() {
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModControl:
|
2020-06-23 01:05:01 -04:00
|
|
|
met.fileIndex--
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModShift:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.levelPreset = decrement(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-07-02 13:55:43 -04:00
|
|
|
default:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.currentRegion = decrement(met.currentRegion, 0, len(regions))
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(met)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-17 08:09:54 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return false
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
|
|
|
func increment(v, min, max int) int {
|
|
|
|
v++
|
|
|
|
if v > max {
|
|
|
|
return min
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func decrement(v, min, max int) int {
|
|
|
|
v--
|
|
|
|
if v < min {
|
|
|
|
return max
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
return v
|
|
|
|
}
|