core.log("error", "[playersettings] Examples are enabled!")

local longdesc =  "Some helpful long description with [];\\[ escaped characters\nLine 2"

-- Wrapper to add logging
local function playersettings_register_logged(setting, def)
	def.onjoin = function(player_name, setting_value)
		core.log("action", ("Callback %s for player=%s: %s=%s"):format(
			"onjoin", player_name, setting, dump(setting_value)))
	end
	def.onchange = function(player_name, old_value, new_value)
		core.log("action", ("Callback %s for player=%s: old=%s, new=%s"):format(
			"onchange", player_name, dump(old_value), dump(new_value)))
		return true -- allow changing
	end
	def.afterchange = function(player_name, old_value, new_value)
		core.log("action", ("Callback %s for player=%s: old=%s, new=%s"):format(
			"afterchange", player_name, dump(old_value), dump(new_value)))
	end

	playersettings.register(setting, def)
end

playersettings_register_logged("playersettings:number", {
	type = "number",
	shortdesc = "Example: number",
	longdesc = longdesc,
	default = 5,
	min = -0.123,
	max = 10,
})

playersettings_register_logged("playersettings:number_integer", {
	type = "number",
	integer = true,
	shortdesc = "Example: number (integer)",
	longdesc = longdesc,
	default = 5,
	min = -10,
	max = 20,
})

playersettings_register_logged("playersettings:string", {
	type = "string",
	shortdesc = "Example: string",
	longdesc = longdesc,
	default = "<default>",
	values = "Input any value."
})

playersettings_register_logged("playersettings:boolean", {
	type = "boolean",
	shortdesc = "Example: boolean",
	longdesc = longdesc,
	default = true,
})

playersettings_register_logged("playersettings:enum", {
	type = "enum",
	shortdesc = "Example: enum",
	longdesc = longdesc,
	default = "apple",
	values = { "apple", "banana", "batman" },
})
