this repo has no description

add persistent configuration #1

merged opened by voigt.tngl.sh targeting main from persistent-config
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:6q572hlx7omtsszji5w2fyw3/sh.tangled.repo.pull/3mgi7r6wnal22
+65
Diff #1
+61
config.go
··· 109 109 type HoldBlockConfig struct { 110 110 Color ff.Color 111 111 } 112 + 113 + const configVersion = 1 114 + 115 + // Save serialises the user-configurable settings to the stash, 116 + // making it available in both single-player and multiplayer. 117 + func (c *Config) Save() { 118 + data := []byte{ 119 + configVersion, 120 + uint8(c.Level), 121 + boolByte(c.DropShadow.Enabled), 122 + boolByte(c.HardDropEnabled), 123 + boolByte(c.HardDropPointsEnabled), 124 + boolByte(c.SoftDropPointsEnabled), 125 + uint8(c.BlockBag), 126 + uint8(c.NextBlock.Count), 127 + uint8(c.Background), 128 + uint8(c.Block.LBlock.Color), 129 + uint8(c.Block.JBlock.Color), 130 + uint8(c.Block.IBlock.Color), 131 + uint8(c.Block.OBlock.Color), 132 + uint8(c.Block.SBlock.Color), 133 + uint8(c.Block.TBlock.Color), 134 + uint8(c.Block.ZBlock.Color), 135 + } 136 + ff.SaveStash(ff.GetMe(), data) 137 + } 138 + 139 + // Load reads previously saved settings from the stash and applies them 140 + // to the config. If no stash exists or the version does not match, 141 + // the defaults already set in config.go are kept unchanged. 142 + func (c *Config) Load() { 143 + data := ff.LoadStash(ff.GetMe(), nil) 144 + if data == nil { 145 + return 146 + } 147 + if len(data) < 16 || data[0] != configVersion { 148 + return 149 + } 150 + c.Level = int(data[1]) 151 + c.DropShadow.Enabled = data[2] != 0 152 + c.HardDropEnabled = data[3] != 0 153 + c.HardDropPointsEnabled = data[4] != 0 154 + c.SoftDropPointsEnabled = data[5] != 0 155 + c.BlockBag = BlockBagType(data[6]) 156 + c.NextBlock.Count = int(data[7]) 157 + c.Background = ff.Color(data[8]) 158 + c.Block.LBlock.Color = ff.Color(data[9]) 159 + c.Block.JBlock.Color = ff.Color(data[10]) 160 + c.Block.IBlock.Color = ff.Color(data[11]) 161 + c.Block.OBlock.Color = ff.Color(data[12]) 162 + c.Block.SBlock.Color = ff.Color(data[13]) 163 + c.Block.TBlock.Color = ff.Color(data[14]) 164 + c.Block.ZBlock.Color = ff.Color(data[15]) 165 + } 166 + 167 + func boolByte(b bool) byte { 168 + if b { 169 + return 1 170 + } 171 + return 0 172 + }
+2
game.go
··· 49 49 FONT = ff.LoadFile("font", nil).Font() 50 50 VERSIONFONT = ff.LoadFile("versionfont", nil).Font() 51 51 52 + CONFIG.Load() 53 + 52 54 ff.LogDebug("Version: " + Version) 53 55 54 56 ff.LogDebug("Register Screens...")
+1
main.go
··· 47 47 ff.Cheat = cheat 48 48 ff.Render = render 49 49 ff.Update = update 50 + ff.BeforeExit = func() { CONFIG.Save() } 50 51 } 51 52 52 53 func cheat(cmd, val int) int {
+1
screen_config.go
··· 392 392 ff.LogDebug("Saving..") 393 393 menuItem := &cs.ConfigList[cs.ConfigListState] 394 394 menuItem.callback(menuItem.values[menuItem.selectedIdx]) 395 + CONFIG.Save() 395 396 } 396 397 397 398 func (cs *ConfigScreen) Update() {

History

2 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
add persistent configuration
expand 0 comments
pull request successfully merged
1 commit
expand
add persistent configuration
expand 0 comments