-
Notifications
You must be signed in to change notification settings - Fork 0
/
tower_adminweb_floor.go
93 lines (83 loc) · 2.63 KB
/
tower_adminweb_floor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2014,2015,2016,2017,2018,2019,2020,2021 SeukWon Kang (kasworld@gmail.com)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tower
import (
"net/http"
"github.com/kasworld/goguelike-single/game/gamei"
"github.com/kasworld/goguelike-single/lib/g2log"
"github.com/kasworld/weblib"
)
func (tw *Tower) getFloorFromHTTPArg(w http.ResponseWriter, r *http.Request) gamei.FloorI {
floorname := weblib.GetStringByName("floorname", "", w, r)
if floorname == "" {
g2log.Warn("Invalid floorname")
http.Error(w, "Invalid floorname", 404)
return nil
}
f := tw.floorMan.GetFloorByName(floorname)
if f == nil {
g2log.Warn("floor not found %v", floorname)
http.Error(w, "floor not found", 404)
return nil
}
return f
}
func (tw *Tower) web_FloorInfo(w http.ResponseWriter, r *http.Request) {
floorname := weblib.GetStringByName("floorname", "", w, r)
if floorname == "" {
g2log.Warn("Invalid floorname")
http.Error(w, "Invalid floorname", 404)
return
}
move := weblib.GetStringByName("move", "", w, r)
var err error
var i int
var f gamei.FloorI
switch move {
case "Before":
i, err = tw.floorMan.GetFloorIndexByName(floorname)
f = tw.floorMan.GetFloorByIndexWrap(i - 1)
case "Next":
i, err = tw.floorMan.GetFloorIndexByName(floorname)
f = tw.floorMan.GetFloorByIndexWrap(i + 1)
default:
f = tw.floorMan.GetFloorByName(floorname)
}
if err != nil {
g2log.Warn("floor not found %v", err)
http.Error(w, "floor not found", 404)
return
}
if f == nil {
g2log.Warn("floor not found %v", floorname)
http.Error(w, "floor not found", 404)
return
}
if err := weblib.SetFresh(w, r); err != nil {
g2log.Error("%v", err)
}
f.Web_FloorInfo(w, r)
}
func (tw *Tower) web_FloorImageZoom(w http.ResponseWriter, r *http.Request) {
if f := tw.getFloorFromHTTPArg(w, r); f != nil {
f.Web_FloorImageZoom(w, r)
}
}
func (tw *Tower) web_FloorImageAutoZoom(w http.ResponseWriter, r *http.Request) {
if f := tw.getFloorFromHTTPArg(w, r); f != nil {
f.Web_FloorImageAutoZoom(w, r)
}
}
func (tw *Tower) web_FloorTile(w http.ResponseWriter, r *http.Request) {
if f := tw.getFloorFromHTTPArg(w, r); f != nil {
f.Web_TileInfo(w, r)
}
}