Go で書き直した Ikemen
Revision | 3bca299fa04a19c608cc8336daf92693637309b3 (tree) |
---|---|
Zeit | 2019-07-30 13:09:15 |
Autor | neatunsou <sisiy4excite@gmai...> |
Commiter | neatunsou |
sffのコピー画像を読み込む際にパレット情報を必ず上書きしていたのを修正
varの情報を保存して読み込む機能を追加
@@ -1,7 +1,9 @@ | ||
1 | 1 | package main |
2 | 2 | |
3 | 3 | import ( |
4 | + "encoding/gob" | |
4 | 5 | "math" |
6 | + "os" | |
5 | 7 | "path/filepath" |
6 | 8 | "unsafe" |
7 | 9 | ) |
@@ -5883,6 +5885,110 @@ func (sc matchRestart) Run(c *Char, _ []int32) bool { | ||
5883 | 5885 | return false |
5884 | 5886 | } |
5885 | 5887 | |
5888 | +type saveFile StateControllerBase | |
5889 | + | |
5890 | +const ( | |
5891 | + saveFile_path byte = iota | |
5892 | + saveFile_saveData | |
5893 | + saveFile_redirectid | |
5894 | +) | |
5895 | + | |
5896 | +func (sc saveFile) Run(c *Char, _ []int32) bool { | |
5897 | + crun := c | |
5898 | + var path string | |
5899 | + var data SaveData | |
5900 | + StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool { | |
5901 | + switch id { | |
5902 | + case saveFile_path: | |
5903 | + path = string(*(*[]byte)(unsafe.Pointer(&exp[0]))) | |
5904 | + case saveFile_saveData: | |
5905 | + data = SaveData(exp[0].evalI(c)) | |
5906 | + case saveFile_redirectid: | |
5907 | + if rid := sys.playerID(exp[0].evalI(c)); rid != nil { | |
5908 | + crun = rid | |
5909 | + } else { | |
5910 | + return false | |
5911 | + } | |
5912 | + } | |
5913 | + return true | |
5914 | + }) | |
5915 | + if path != "" { | |
5916 | + encodeFile, err := os.Create(filepath.Dir(c.gi().def) + "/" + path) | |
5917 | + if err != nil { | |
5918 | + panic(err) | |
5919 | + } | |
5920 | + defer encodeFile.Close() | |
5921 | + encoder := gob.NewEncoder(encodeFile) | |
5922 | + switch data { | |
5923 | + case SaveData_map: | |
5924 | + if err := encoder.Encode(crun.mapArray); err != nil { | |
5925 | + panic(err) | |
5926 | + } | |
5927 | + case SaveData_var: | |
5928 | + if err := encoder.Encode(crun.ivar); err != nil { | |
5929 | + panic(err) | |
5930 | + } | |
5931 | + case SaveData_fvar: | |
5932 | + if err := encoder.Encode(crun.fvar); err != nil { | |
5933 | + panic(err) | |
5934 | + } | |
5935 | + } | |
5936 | + } | |
5937 | + return false | |
5938 | +} | |
5939 | + | |
5940 | +type loadFile StateControllerBase | |
5941 | + | |
5942 | +const ( | |
5943 | + loadFile_path byte = iota | |
5944 | + loadFile_saveData | |
5945 | + loadFile_redirectid | |
5946 | +) | |
5947 | + | |
5948 | +func (sc loadFile) Run(c *Char, _ []int32) bool { | |
5949 | + crun := c | |
5950 | + var path string | |
5951 | + var data SaveData | |
5952 | + StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool { | |
5953 | + switch id { | |
5954 | + case loadFile_path: | |
5955 | + path = string(*(*[]byte)(unsafe.Pointer(&exp[0]))) | |
5956 | + case loadFile_saveData: | |
5957 | + data = SaveData(exp[0].evalI(c)) | |
5958 | + case loadFile_redirectid: | |
5959 | + if rid := sys.playerID(exp[0].evalI(c)); rid != nil { | |
5960 | + crun = rid | |
5961 | + } else { | |
5962 | + return false | |
5963 | + } | |
5964 | + } | |
5965 | + return true | |
5966 | + }) | |
5967 | + if path != "" { | |
5968 | + decodeFile, err := os.Open(filepath.Dir(c.gi().def) + "/" + path) | |
5969 | + if err != nil { | |
5970 | + panic(err) | |
5971 | + } | |
5972 | + defer decodeFile.Close() | |
5973 | + decoder := gob.NewDecoder(decodeFile) | |
5974 | + switch data { | |
5975 | + case SaveData_map: | |
5976 | + if err := decoder.Decode(&crun.mapArray); err != nil { | |
5977 | + panic(err) | |
5978 | + } | |
5979 | + case SaveData_var: | |
5980 | + if err := decoder.Decode(&crun.ivar); err != nil { | |
5981 | + panic(err) | |
5982 | + } | |
5983 | + case SaveData_fvar: | |
5984 | + if err := decoder.Decode(&crun.fvar); err != nil { | |
5985 | + panic(err) | |
5986 | + } | |
5987 | + } | |
5988 | + } | |
5989 | + return false | |
5990 | +} | |
5991 | + | |
5886 | 5992 | type StateBytecode struct { |
5887 | 5993 | stateType StateType |
5888 | 5994 | moveType MoveType |
@@ -90,6 +90,14 @@ const ( | ||
90 | 90 | Space_screen |
91 | 91 | ) |
92 | 92 | |
93 | +type SaveData int32 | |
94 | + | |
95 | +const ( | |
96 | + SaveData_map SaveData = iota | |
97 | + SaveData_var | |
98 | + SaveData_fvar | |
99 | +) | |
100 | + | |
93 | 101 | type ClsnRect [][4]float32 |
94 | 102 | |
95 | 103 | func (cr *ClsnRect) Add(clsn []float32, x, y, xs, ys float32) { |
@@ -126,6 +126,8 @@ func newCompiler() *Compiler { | ||
126 | 126 | "zoom": c.zoom, |
127 | 127 | "mapset": c.mapSet, |
128 | 128 | "matchrestart": c.matchRestart, |
129 | + "savefile": c.saveFile, | |
130 | + "loadfile": c.loadFile, | |
129 | 131 | "forcefeedback": c.null, |
130 | 132 | "null": c.null, |
131 | 133 | } |
@@ -2808,6 +2810,27 @@ func (c *Compiler) paramSpace(is IniSection, sc *StateControllerBase, | ||
2808 | 2810 | }) |
2809 | 2811 | } |
2810 | 2812 | |
2813 | +func (c *Compiler) paramSaveData(is IniSection, sc *StateControllerBase, | |
2814 | + id byte) error { | |
2815 | + return c.stateParam(is, "savedata", func(data string) error { | |
2816 | + if len(data) <= 1 { | |
2817 | + return Error("値が指定されていません") | |
2818 | + } | |
2819 | + var sv SaveData | |
2820 | + if len(data) >= 2 { | |
2821 | + if strings.ToLower(data[:2]) == "ma" { | |
2822 | + sv = SaveData_map | |
2823 | + } else if strings.ToLower(data[:2]) == "va" { | |
2824 | + sv = SaveData_var | |
2825 | + } else if strings.ToLower(data[:2]) == "fv" { | |
2826 | + sv = SaveData_fvar | |
2827 | + } | |
2828 | + } | |
2829 | + sc.add(id, sc.iToExp(int32(sv))) | |
2830 | + return nil | |
2831 | + }) | |
2832 | +} | |
2833 | + | |
2811 | 2834 | func (c *Compiler) paramTrans(is IniSection, sc *StateControllerBase, |
2812 | 2835 | prefix string, id byte, afterImage bool) error { |
2813 | 2836 | return c.stateParam(is, prefix+"trans", func(data string) error { |
@@ -6381,6 +6404,54 @@ func (c *Compiler) matchRestart(is IniSection, sc *StateControllerBase, | ||
6381 | 6404 | return *ret, err |
6382 | 6405 | } |
6383 | 6406 | |
6407 | +func (c *Compiler) saveFile(is IniSection, sc *StateControllerBase, | |
6408 | + _ int8) (StateController, error) { | |
6409 | + ret, err := (*saveFile)(sc), c.stateSec(is, func() error { | |
6410 | + if err := c.paramValue(is, sc, "redirectid", | |
6411 | + saveFile_redirectid, VT_Int, 1, false); err != nil { | |
6412 | + return err | |
6413 | + } | |
6414 | + if err := c.stateParam(is, "path", func(data string) error { | |
6415 | + if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { | |
6416 | + return Error("\"で囲まれていません") | |
6417 | + } | |
6418 | + sc.add(saveFile_path, sc.beToExp(BytecodeExp(data[1:len(data)-1]))) | |
6419 | + return nil | |
6420 | + }); err != nil { | |
6421 | + return err | |
6422 | + } | |
6423 | + if err := c.paramSaveData(is, sc, saveFile_saveData); err != nil { | |
6424 | + return err | |
6425 | + } | |
6426 | + return nil | |
6427 | + }) | |
6428 | + return *ret, err | |
6429 | +} | |
6430 | + | |
6431 | +func (c *Compiler) loadFile(is IniSection, sc *StateControllerBase, | |
6432 | + _ int8) (StateController, error) { | |
6433 | + ret, err := (*loadFile)(sc), c.stateSec(is, func() error { | |
6434 | + if err := c.paramValue(is, sc, "redirectid", | |
6435 | + loadFile_redirectid, VT_Int, 1, false); err != nil { | |
6436 | + return err | |
6437 | + } | |
6438 | + if err := c.stateParam(is, "path", func(data string) error { | |
6439 | + if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { | |
6440 | + return Error("\"で囲まれていません") | |
6441 | + } | |
6442 | + sc.add(loadFile_path, sc.beToExp(BytecodeExp(data[1:len(data)-1]))) | |
6443 | + return nil | |
6444 | + }); err != nil { | |
6445 | + return err | |
6446 | + } | |
6447 | + if err := c.paramSaveData(is, sc, loadFile_saveData); err != nil { | |
6448 | + return err | |
6449 | + } | |
6450 | + return nil | |
6451 | + }) | |
6452 | + return *ret, err | |
6453 | +} | |
6454 | + | |
6384 | 6455 | func (c *Compiler) null(is IniSection, sc *StateControllerBase, |
6385 | 6456 | _ int8) (StateController, error) { |
6386 | 6457 | return nullStateController, nil |
@@ -513,7 +513,9 @@ func (s *Sprite) shareCopy(src *Sprite) { | ||
513 | 513 | s.Pal = src.Pal |
514 | 514 | s.Tex = src.Tex |
515 | 515 | s.Size = src.Size |
516 | - s.palidx = src.palidx | |
516 | + if s.palidx < 0 { | |
517 | + s.palidx = src.palidx | |
518 | + } | |
517 | 519 | } |
518 | 520 | func (s *Sprite) GetPal(pl *PaletteList) []uint32 { |
519 | 521 | if s.Pal != nil || s.rle <= -11 { |
@@ -64,15 +64,15 @@ var sys = System{ | ||
64 | 64 | keyInput: glfw.KeyUnknown, |
65 | 65 | keyString: "", |
66 | 66 | // Localcoord sceenpack |
67 | - luaSpriteScale: 1, | |
68 | - luaSmallPortraitScale: 1, | |
69 | - luaBigPortraitScale: 1, | |
70 | - luaSpriteOffsetX: 0, | |
71 | - lifebarScale: 1, | |
72 | - lifebarOffsetX: 0, | |
67 | + luaSpriteScale: 1, | |
68 | + luaSmallPortraitScale: 1, | |
69 | + luaBigPortraitScale: 1, | |
70 | + luaSpriteOffsetX: 0, | |
71 | + lifebarScale: 1, | |
72 | + lifebarOffsetX: 0, | |
73 | 73 | //Shader vars |
74 | 74 | MultisampleAntialiasing: false, |
75 | - PostProcessingShader: 0, | |
75 | + PostProcessingShader: 0, | |
76 | 76 | } |
77 | 77 | |
78 | 78 | type TeamMode int32 |
@@ -256,7 +256,7 @@ type System struct { | ||
256 | 256 | lifebarOffsetX float32 |
257 | 257 | LocalcoordScalingType int32 |
258 | 258 | |
259 | - PostProcessingShader int32 | |
259 | + PostProcessingShader int32 | |
260 | 260 | MultisampleAntialiasing bool |
261 | 261 | } |
262 | 262 |