MCPcopy Create free account
hub / github.com/ddnet/ddnet / export_settings

Function export_settings

scripts/export_settings_commands_table.py:141–174  ·  view source on GitHub ↗
(parsed_settings)

Source from the content-addressed store, hash-verified

139
140
141def export_settings(parsed_settings):
142 def export_color_value(setting):
143 alpha = "CFGFLAG_COLALPHA" in setting["flags"]
144 if "CFGFLAG_COLLIGHT7" in setting["flags"]:
145 darkest_lgt = 61.0 / 255.0
146 elif "CFGFLAG_COLLIGHT" in setting["flags"]:
147 darkest_lgt = 0.5
148 else:
149 darkest_lgt = 0.0
150 number = setting["default"]
151 a = ((number >> 24) & 0xFF) / 255.0 if alpha else 1.0
152 h = ((number >> 16) & 0xFF) / 255.0
153 s = ((number >> 8) & 0xFF) / 255.0
154 l = (number & 0xFF) / 255.0
155 l = darkest_lgt + l * (1.0 - darkest_lgt)
156 return f'<span class="colorpreview" style="background: hsla({h * 360.0:.3f}, {s * 100.0:.3f}%, {l * 100.0:.3f}%, {a:.3f})"></span> {number}'
157
158 output = ['<div style="overflow-x: auto;"><table class="settingscommands">']
159 output.append(" <tr><th>Setting</th><th>Description</th><th>Default</th><th>Min</th><th>Max</th></tr>")
160
161 for setting in parsed_settings:
162 line = f" <tr><td>{html.escape(setting['name'])}</td><td>{html.escape(setting['description'])}</td>"
163 if setting["type"] == "string":
164 line = line + f"<td>{html.escape(setting['default'])}</td><td></td><td></td></tr>"
165 elif setting["type"] == "int":
166 line = line + f"<td>{setting['default']}</td><td>{setting['min']}</td><td>{setting['max']}</td></tr>"
167 elif setting["type"] == "color":
168 line = line + f"<td>{export_color_value(setting)}</td><td></td><td></td></tr>"
169 else:
170 raise RuntimeError(f"Unhandled setting type: {setting['type']}")
171 output.append(line)
172
173 output.append("</table></div>")
174 return "\n".join(output)
175
176
177def export_tunings(parsed_tunings):

Callers 1

Calls 1

export_color_valueFunction · 0.85

Tested by

no test coverage detected