• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Go で書き直した Ikemen


Commit MetaInfo

Revisãoef94d4fe26dee96d686100aba6e803e7906df0b4 (tree)
Hora2016-11-27 00:08:03
AutorSUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Mensagem de Log

windows用のdefファイルを読み込みたい

Mudança Sumário

Diff

--- a/run.sh
+++ b/run.sh
@@ -3,4 +3,4 @@ GOPATH=$PWD/go
33 export GOPATH
44 go fmt ./src/*.go
55 # godoc -src ./src .* > godoc.txt
6-go generate ./src/main.go && GODEBUG=cgocheck=0 go run ./src/*.go
6+go generate ./src/main.go && go run ./src/*.go
--- a/src/common.go
+++ b/src/common.go
@@ -5,13 +5,14 @@ import (
55 "io/ioutil"
66 "math"
77 "os"
8+ "path/filepath"
89 "strings"
10+ "unicode"
911 )
1012
1113 const (
12- IMax = int32(^uint32(0) >> 1)
13- IErr = ^IMax
14- PathDelimiters = "/\\"
14+ IMax = int32(^uint32(0) >> 1)
15+ IErr = ^IMax
1516 )
1617
1718 var randseed int32
@@ -176,22 +177,58 @@ func LoadText(filename string) (string, error) {
176177 return AsciiToString(bytes), nil
177178 }
178179 func LoadFile(file *string, deffile string, load func(string) error) error {
179- var filepath string
180- if li := strings.LastIndexAny(deffile, PathDelimiters); li >= 0 {
181- filepath = deffile[:li+1] + *file
182- if _, err := os.Stat(filepath); os.IsNotExist(err) {
183- filepath = "data/" + *file
180+ var fp string
181+ isNotExist := func() bool {
182+ if _, err := os.Stat(fp); !os.IsNotExist(err) {
183+ return false
184184 }
185+ var pattern string
186+ for _, r := range fp {
187+ if r >= 'A' && r <= 'Z' || r >= 'a' && r <= 'z' {
188+ pattern += "[" + string(unicode.ToLower(r)) +
189+ string(unicode.ToLower(r)+'A'-'a') + "]"
190+ } else if r == '*' || r == '?' || r == '[' {
191+ pattern += "\\" + string(r)
192+ } else {
193+ pattern += string(r)
194+ }
195+ }
196+ if m, _ := filepath.Glob(pattern); len(m) > 0 {
197+ fp = m[0]
198+ return false
199+ }
200+ return true
201+ }
202+ *file = strings.Replace(*file, "\\", "/", -1)
203+ defdir := filepath.Dir(strings.Replace(deffile, "\\", "/", -1))
204+ if defdir == "." {
205+ fp = *file
206+ } else if defdir == "/" {
207+ fp = defdir + *file
185208 } else {
186- filepath = "data/" + *file
187- }
188- if _, err := os.Stat(filepath); os.IsNotExist(err) {
189- filepath = *file
209+ fp = defdir + "/" + *file
210+ }
211+ if isNotExist() {
212+ _else := false
213+ if defdir != "data" {
214+ fp = "data/" + *file
215+ if isNotExist() {
216+ _else = true
217+ }
218+ } else {
219+ _else = true
220+ }
221+ if _else {
222+ if defdir != "." {
223+ fp = *file
224+ isNotExist()
225+ }
226+ }
190227 }
191- if err := load(filepath); err != nil {
192- return Error(fmt.Sprintf("%s:\n%s", filepath, err.Error()))
228+ if err := load(fp); err != nil {
229+ return Error(fmt.Sprintf("%s:\n%s", fp, err.Error()))
193230 }
194- *file = filepath
231+ *file = fp
195232 return nil
196233 }
197234 func SplitAndTrim(str, sep string) (ss []string) {
@@ -315,20 +352,23 @@ func readLayout(pre string, is IniSection) *Layout {
315352 l := newLayout()
316353 is.ReadF32(pre+"offset", &l.offset[0], &l.offset[1])
317354 is.ReadI32(pre+"displaytime", &l.displaytime)
318- if str := is["facing"]; len(str) > 0 {
355+ if str := is[pre+"facing"]; len(str) > 0 {
319356 if Atoi(str) < 0 {
320357 l.facing = -1
321358 } else {
322359 l.facing = 1
323360 }
324361 }
325- if str := is["vfacing"]; len(str) > 0 {
362+ if str := is[pre+"vfacing"]; len(str) > 0 {
326363 if Atoi(str) < 0 {
327364 l.vfacing = -1
328365 } else {
329366 l.vfacing = 1
330367 }
331368 }
369+ var ln int32
370+ is.ReadI32(pre+"layerno", &ln)
371+ l.layerno = I32ToI16(Min(2, ln))
332372 is.ReadF32(pre+"scale", &l.scale[0], &l.scale[1])
333373 return l
334374 }