mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-05 01:37:17 -05:00
add map switcher (#162)
This commit is contained in:
parent
055fcd72ed
commit
78a70c2d2b
@ -180,7 +180,7 @@ func (v *MainMenu) Load() []func() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onMapTestClicked() {
|
||||
v.sceneProvider.SetNextScene(CreateMapEngineTest(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
|
||||
v.sceneProvider.SetNextScene(CreateMapEngineTest(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager, 0))
|
||||
}
|
||||
|
||||
func openbrowser(url string) {
|
||||
|
@ -11,10 +11,12 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
_map "github.com/OpenDiablo2/OpenDiablo2/d2render/d2mapengine"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type MapEngineTest struct {
|
||||
@ -24,23 +26,61 @@ type MapEngineTest struct {
|
||||
sceneProvider d2interface.SceneProvider
|
||||
gameState *d2core.GameState
|
||||
mapEngine *_map.Engine
|
||||
currentRegion int
|
||||
keyLocked bool
|
||||
}
|
||||
|
||||
func CreateMapEngineTest(
|
||||
fileProvider d2interface.FileProvider,
|
||||
sceneProvider d2interface.SceneProvider,
|
||||
uiManager *d2ui.Manager,
|
||||
soundManager *d2audio.Manager) *MapEngineTest {
|
||||
soundManager *d2audio.Manager,
|
||||
currentRegion int) *MapEngineTest {
|
||||
result := &MapEngineTest{
|
||||
fileProvider: fileProvider,
|
||||
uiManager: uiManager,
|
||||
soundManager: soundManager,
|
||||
sceneProvider: sceneProvider,
|
||||
currentRegion: currentRegion,
|
||||
keyLocked: false,
|
||||
}
|
||||
result.gameState = d2core.CreateTestGameState()
|
||||
return result
|
||||
}
|
||||
|
||||
type RegionSpec struct {
|
||||
regionType d2enum.RegionIdType
|
||||
levelPreset int
|
||||
}
|
||||
|
||||
var regions []RegionSpec = []RegionSpec{
|
||||
{d2enum.RegionAct1Tristram, 300},
|
||||
{d2enum.RegionAct1Cathedral, 257},
|
||||
{d2enum.RegionAct2Town, 301},
|
||||
// {d2enum.RegionAct2Harem, 353},
|
||||
{d2enum.RegionAct3Town, 529},
|
||||
{d2enum.RegionAct3Jungle, 574},
|
||||
{d2enum.RegionAct4Town, 797},
|
||||
{d2enum.RegonAct5Town, 863},
|
||||
{d2enum.RegionAct5IceCaves, 1038},
|
||||
{d2enum.RegionAct5Siege, 879},
|
||||
{d2enum.RegionAct5Lava, 105},
|
||||
{d2enum.RegionAct5Barricade, 880},
|
||||
}
|
||||
|
||||
func (v *MapEngineTest) LoadRegionByIndex(n int) {
|
||||
if n == 0 {
|
||||
v.mapEngine.GenerateAct1Overworld()
|
||||
return
|
||||
}
|
||||
region := regions[n-1]
|
||||
|
||||
v.mapEngine = _map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider) // necessary for map name update
|
||||
v.mapEngine.OffsetY = 0
|
||||
v.mapEngine.OffsetX = 0
|
||||
v.mapEngine.GenerateMap(region.regionType, region.levelPreset)
|
||||
}
|
||||
|
||||
func (v *MapEngineTest) Load() []func() {
|
||||
// TODO: Game seed comes from the game state object
|
||||
|
||||
@ -49,19 +89,20 @@ func (v *MapEngineTest) Load() []func() {
|
||||
func() {
|
||||
v.mapEngine = _map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider)
|
||||
|
||||
v.mapEngine.GenerateAct1Overworld()
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct1Tristram, 300)
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct1Cathedral, 257)
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct2Town, 301)
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct2Harem, 353) // Crashes on dcc load
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct3Town, 529)
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct3Jungle, 574)
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct4Town, 797) // Broken height of large objects
|
||||
//v.mapEngine.GenerateMap(Map.RegonAct5Town, 863) // Completely broken!!
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct5IceCaves, 1038) // Completely broken!
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct5Siege, 879) // Completely broken!
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct5Lava, 1057) // Broken
|
||||
//v.mapEngine.GenerateMap(Map.RegionAct5Barricade, 880) // Broken
|
||||
v.LoadRegionByIndex(v.currentRegion)
|
||||
// v.mapEngine.GenerateAct1Overworld()
|
||||
// v.mapEngine.GenerateMap(d2enum.RegionAct1Tristram, 300)
|
||||
// v.mapEngine.GenerateMap(d2enum.RegionAct1Cathedral, 257)
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct2Town, 301)
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct2Harem, 353) // Crashes on dcc load
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct3Town, 529)
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct3Jungle, 574)
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct4Town, 797) // Broken height of large objects
|
||||
//v.mapEngine.GenerateMap(d2enum.RegonAct5Town, 863) // Completely broken!!
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct5IceCaves, 1038) // Completely broken!
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct5Siege, 879) // Completely broken!
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct5Lava, 1057) // Broken
|
||||
//v.mapEngine.GenerateMap(d2enum.RegionAct5Barricade, 880) // Broken
|
||||
|
||||
},
|
||||
}
|
||||
@ -92,7 +133,8 @@ func (v *MapEngineTest) Render(screen *ebiten.Image) {
|
||||
)
|
||||
ebitenutil.DebugPrintAt(screen, line, 5, 5)
|
||||
ebitenutil.DebugPrintAt(screen, "Map: "+curRegion.Region.LevelType.Name, 5, 17)
|
||||
ebitenutil.DebugPrintAt(screen, curRegion.Region.RegionPath, 5, 29)
|
||||
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("%v [%v]", curRegion.Region.RegionPath, v.currentRegion), 5, 29)
|
||||
ebitenutil.DebugPrintAt(screen, "N - next map, P - previous map", 5, 41)
|
||||
}
|
||||
|
||||
func (v *MapEngineTest) Update(tickTime float64) {
|
||||
@ -108,4 +150,33 @@ func (v *MapEngineTest) Update(tickTime float64) {
|
||||
if v.uiManager.KeyPressed(ebiten.KeyRight) {
|
||||
v.mapEngine.OffsetX -= tickTime * 800
|
||||
}
|
||||
if v.uiManager.KeyPressed(ebiten.KeyEscape) {
|
||||
os.Exit(0)
|
||||
}
|
||||
if v.uiManager.KeyPressed(ebiten.KeyN) && !v.keyLocked {
|
||||
v.currentRegion++
|
||||
if v.currentRegion == len(regions) {
|
||||
v.currentRegion = 0
|
||||
}
|
||||
v.keyLocked = true
|
||||
fmt.Println("---")
|
||||
v.sceneProvider.SetNextScene(v)
|
||||
return
|
||||
}
|
||||
|
||||
if v.uiManager.KeyPressed(ebiten.KeyP) && !v.keyLocked {
|
||||
v.currentRegion--
|
||||
if v.currentRegion == -1 {
|
||||
v.currentRegion = len(regions) - 1
|
||||
}
|
||||
v.keyLocked = true
|
||||
fmt.Println("---")
|
||||
v.sceneProvider.SetNextScene(v)
|
||||
return
|
||||
}
|
||||
|
||||
//FIXME: do it better
|
||||
if !v.uiManager.KeyPressed(ebiten.KeyP) && !v.uiManager.KeyPressed(ebiten.KeyN) {
|
||||
v.keyLocked = false
|
||||
}
|
||||
}
|
||||
|
@ -128,9 +128,10 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
||||
continue
|
||||
}
|
||||
v.Files[fileName] = path.Join(v.Settings.MpqPath, mpqFile)
|
||||
// log.Printf("%v in %v", fileName, mpqFile)
|
||||
return result
|
||||
}
|
||||
log.Fatalf("Could not load %s from MPQs", fileName)
|
||||
log.Printf("Could not load %s from MPQs\n", fileName)
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,9 @@ type COF struct {
|
||||
func LoadCOF(fileName string, fileProvider d2interface.FileProvider) *COF {
|
||||
result := &COF{}
|
||||
fileData := fileProvider.LoadFile(fileName)
|
||||
if len(fileData) == 0 {
|
||||
return result
|
||||
}
|
||||
streamReader := d2common.CreateStreamReader(fileData)
|
||||
result.NumberOfLayers = int(streamReader.GetByte())
|
||||
result.FramesPerDirection = int(streamReader.GetByte())
|
||||
|
@ -24,6 +24,11 @@ func (v DCC) IsValid() bool {
|
||||
func LoadDCC(path string, fileProvider d2interface.FileProvider) DCC {
|
||||
result := DCC{}
|
||||
fileData := fileProvider.LoadFile(path)
|
||||
if len(fileData) == 0 {
|
||||
ret := DCC{}
|
||||
ret.valid = false
|
||||
return ret
|
||||
}
|
||||
var bm = d2common.CreateBitMuncher(fileData, 0)
|
||||
result.Signature = int(bm.GetByte())
|
||||
if result.Signature != 0x74 {
|
||||
|
@ -151,9 +151,14 @@ func (v *Region) renderFloor(tile d2ds1.FloorShadowRecord, offsetX, offsetY int,
|
||||
v.FloorCache[tileCacheIndex] = v.generateFloorCache(tile)
|
||||
tileCache = v.FloorCache[tileCacheIndex]
|
||||
if tileCache == nil {
|
||||
log.Fatal("Could not load floor tile")
|
||||
log.Println("Could not load floor tile")
|
||||
return
|
||||
}
|
||||
}
|
||||
if tileCache == nil {
|
||||
log.Println("Nil tile cache")
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
opts.GeoM.Translate(float64(offsetX+tileCache.XOffset), float64(offsetY+tileCache.YOffset))
|
||||
target.DrawImage(tileCache.Image, opts)
|
||||
@ -165,10 +170,15 @@ func (v *Region) renderWall(tile d2ds1.WallRecord, offsetX, offsetY int, target
|
||||
if !exists {
|
||||
v.WallCache[tileCacheIndex] = v.generateWallCache(tile)
|
||||
if v.WallCache[tileCacheIndex] == nil {
|
||||
log.Fatal("Could not generate wall")
|
||||
log.Println("Could not generate wall")
|
||||
return
|
||||
}
|
||||
tileCache = v.WallCache[tileCacheIndex]
|
||||
}
|
||||
if tileCache == nil {
|
||||
log.Println("Nil tile cache")
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
opts.GeoM.Translate(float64(offsetX+tileCache.XOffset), float64(offsetY+tileCache.YOffset))
|
||||
target.DrawImage(tileCache.Image, opts)
|
||||
@ -181,9 +191,14 @@ func (v *Region) renderShadow(tile d2ds1.FloorShadowRecord, offsetX, offsetY int
|
||||
v.ShadowCache[tileCacheIndex] = v.generateShadowCache(tile)
|
||||
tileCache = v.ShadowCache[tileCacheIndex]
|
||||
if tileCache == nil {
|
||||
log.Fatal("Could not load shadow tile")
|
||||
log.Println("Could not load shadow tile")
|
||||
return
|
||||
}
|
||||
}
|
||||
if tileCache == nil {
|
||||
log.Println("Nil tile cache")
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
opts.GeoM.Translate(float64(offsetX+tileCache.XOffset), float64(offsetY+tileCache.YOffset))
|
||||
opts.ColorM = d2helper.ColorToColorM(color.RGBA{255, 255, 255, 160})
|
||||
@ -265,7 +280,10 @@ func (v *Region) decodeTileGfxData(blocks []d2dt1.Block, pixels []byte, tileYOff
|
||||
func (v *Region) generateFloorCache(tile d2ds1.FloorShadowRecord) *TileCacheRecord {
|
||||
tileData := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), 0)
|
||||
if tileData == nil {
|
||||
log.Fatalf("Could not locate tile Idx:%d, Sub: %d, Ori: %d", tile.MainIndex, tile.SubIndex, 0)
|
||||
log.Printf("Could not locate tile Idx:%d, Sub: %d, Ori: %d\n", tile.MainIndex, tile.SubIndex, 0)
|
||||
tileData = &d2dt1.Tile{}
|
||||
tileData.Width = 10
|
||||
tileData.Height = 10
|
||||
}
|
||||
tileYMinimum := int32(0)
|
||||
for _, block := range tileData.Blocks {
|
||||
|
Loading…
Reference in New Issue
Block a user