aboutsummaryrefslogtreecommitdiff
path: root/src/quicktune_shortcutter.h
blob: a6cb71ed6d68845258a53886dd095217a414b519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Minetest-c55
Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef QVT_SHORTCUTTER_HEADER
#define QVT_SHORTCUTTER_HEADER

#include "quicktune.h"
#include "utility.h"

class QuicktuneShortcutter
{
private:
	std::vector<std::string> m_names;
	u32 m_selected_i;
	std::string m_message;
public:
	std::string getMessage()
	{
		std::string s = m_message;
		m_message = "";
		if(s != "")
			return std::string("[quicktune] ") + s;
		return "";
	}
	std::string getSelectedName()
	{
		if(m_selected_i < m_names.size())
			return m_names[m_selected_i];
		return "(nothing)";
	}
	void next()
	{
		m_names = getQuicktuneNames();
		if(m_selected_i < m_names.size()-1)
			m_selected_i++;
		else
			m_selected_i = 0;
		m_message = std::string("Selected \"")+getSelectedName()+"\"";
	}
	void prev()
	{
		m_names = getQuicktuneNames();
		if(m_selected_i > 0)
			m_selected_i--;
		else
			m_selected_i = m_names.size()-1;
		m_message = std::string("Selected \"")+getSelectedName()+"\"";
	}
	void inc()
	{
		QuicktuneValue val = getQuicktuneValue(getSelectedName());
		val.relativeAdd(0.05);
		m_message = std::string("\"")+getSelectedName()
				+"\" = "+val.getString();
		setQuicktuneValue(getSelectedName(), val);
	}
	void dec()
	{
		QuicktuneValue val = getQuicktuneValue(getSelectedName());
		val.relativeAdd(-0.05);
		m_message = std::string("\"")+getSelectedName()
				+"\" = "+val.getString();
		setQuicktuneValue(getSelectedName(), val);
	}
};

#endif

class="hl slc">-- First phase, list the tables and functions which appear more than -- once in x. local function mark_multiple_occurences(x) local tp = type(x) if tp ~= "table" and tp ~= "function" then -- No identity (comparison is done by value, not by instance) return end if seen[x] == 1 then seen[x] = 2 elseif seen[x] ~= 2 then seen[x] = 1 end if tp == "table" then nested[x] = true for k, v in pairs(x) do if nested[k] or nested[v] then mark_nest_point(x, k, v) else mark_multiple_occurences(k) mark_multiple_occurences(v) end end nested[x] = nil end end local dumped = {} -- object->varname set local local_defs = {} -- Dumped local definitions as source code lines -- Mutually recursive local functions: local dump_val, dump_or_ref_val -- If x occurs multiple times, dump the local variable rather than -- the value. If it's the first time it's dumped, also dump the -- content in local_defs. function dump_or_ref_val(x) if seen[x] ~= 2 then return dump_val(x) end local var = dumped[x] if var then -- Already referenced return var end -- First occurence, create and register reference local val = dump_val(x) local i = local_index local_index = local_index + 1 var = "_["..i.."]" local_defs[#local_defs + 1] = var.." = "..val dumped[x] = var return var end -- Second phase. Dump the object; subparts occuring multiple times -- are dumped in local variables which can be referenced multiple -- times. Care is taken to dump local vars in a sensible order. function dump_val(x) local tp = type(x) if x == nil then return "nil" elseif tp == "string" then return string.format("%q", x) elseif tp == "boolean" then return x and "true" or "false" elseif tp == "function" then return string.format("loadstring(%q)", string.dump(x)) elseif tp == "number" then -- Serialize numbers reversibly with string.format return string.format("%.17g", x) elseif tp == "table" then local vals = {} local idx_dumped = {} local np = nest_points[x] for i, v in ipairs(x) do if not np or not np[i] then vals[#vals + 1] = dump_or_ref_val(v) end idx_dumped[i] = true