File: functions.cfg

package info (click to toggle)
frogatto-data 1.3.1%2Bdfsg-4
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 254,428 kB
  • sloc: xml: 584; python: 396; perl: 249; sh: 126; ruby: 69; makefile: 21
file content (252 lines) | stat: -rw-r--r-- 8,032 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
[	
	{
		name: "send_to_coordinates",
		args: "obj,gotx,goty,vel",
		formula: "[
			set(obj.velocity_x,cos(angle(obj.midpoint_x,obj.midpoint_y,gotx,goty))*vel),
			set(obj.velocity_y,sin(angle(obj.midpoint_x,obj.midpoint_y,gotx,goty))*vel)]",
	},
	{
		name: "set_relative_velocity",
		args: "obj, vel",
		formula: "send_to_coordinates(obj,rotx,roty,vel)
			where rotx = ((obj.midpoint_y+1)*sin(-obj.rotate) + obj.midpoint_x)
			where roty = ((obj.midpoint_y+1)*cos(-obj.rotate) + obj.midpoint_y)",
	},
	
	{
		name: "obj_strs",
		args: "obj",
		formula: "'(obj ${obj.label}:\n    type=${obj.type},\n    animation=${obj.animation},\n    pos=[${obj.midpoint_x},${obj.midpoint_y}],\n    cycle=${obj.cycle},\n    active=${obj.active})'",
	},

	"@flatten",
	"@include data/functions-math.cfg",
	"@include data/functions-time.cfg",
	"@include data/functions-geometry.cfg",
	"@include data/functions-list.cfg",
	
	{

		#list:	A list of something to be added into sum.
		#sum:	An empty member of a type which is addition-compatible with all members of the list.
		name: "flex_sum",
		args: "list, sum",
		//formula: "if(size(list), flex_sum(list[1:size(list)], sum+list[0]) ,sum)",
		formula: "fold(list or []+[sum], a+b)",
	},
	
	{
		name: "map_merge",
		args: "map1, map2",
		formula: "zip(map1, map2, a+b)",
	},

	#each element in data overwrites each element in list, starting with the element at index. If index is out of bounds or the data does not fit in the list, Bad Stuff Happens™.
	#eg., args [1,2,3,4,5], 2, ['a', 'b'] would return [1,2,'a','b',5].
	{
		name: "list_replace_elements",
		args: "list, index, data_",
		formula: "list[0:index] + data + list[index+size(data):size(list)] where data = if(is_list(data_), data_, [data_])",
	},
	{
		name: "list_get_random",
		args: "list",
		formula: "list[(1 d size(list)) - 1]",
	},
	{
		name: "_list_cat",
		args: "list, sum, delim",
		formula: "if(size(list) > 0, _list_cat(list[1:size(list)], if(sum = '', str(list[0]), sum + str(list[0])) + if(size(list) > 1, delim, ''), delim), sum)",
	},
	{
		name: "list_cat",
		args: "list",
		formula: "_list_cat(list, '', '')",
	},
	{
		name: "list_cat_delim",
		args: "list, delim",
		formula: "_list_cat(list, '', delim)",
	},
	{
		name: "join",
		args: "list",
		formula: "list_cat(list)",
	},
	{
		name: "join_d",
		args: "list, delim",
		formula: "list_cat_delim(list, delim)",
	},
	{
		#Given a list and an index, return [the object at that index, the rest of the list without that object]
		name: "list_pop",
		args: "list, index",
		formula: "[list[index], list[0:index] + list[index+1:size(list)]]",
	},
	{
		name: "best_between",
		args: "list1, list2, criteria",
		formula: "transform(range(size(list1)), if(criteria(list1[v], list2[v]), list1[v], list2[v]))",
	},
	{
		name: "best_of",
		args: "lists, criteria",
		formula: "switch(size(lists), 
			0, [],
			1, lists[0],
			2, best_between(lists[0], lists[1], criteria),
			best_between(lists[0], best_of(lists[1:size(lists)], criteria), criteria))",
	},
	{
		name: "_zip_with",
		args: "list1, list2, criteria",
		formula: "transform(range(size(list1)), criteria(list1[v], list2[v]))",
	},
	{
		name: "zip_with",
		args: "lists, criteria",
		formula: "switch(size(lists),
			0, [],
			1, lists[0],
			2, _zip_with(lists[0], lists[1], criteria),
			_zip_with(lists[0], zip_with(lists[1:size(lists)], criteria), criteria))",
	},
	{
		#list - a list of stuff to apply a function to, and so collapse to one value.
		#method - the /property/, taking two args, with which to collapse the list. Must be a property as defined by def(). The things in this file are functions, and will not work. However, they may be called from properties.
		#Reduces list by calling /method/ with the first arg being the first element of the list and the second arg being the reduction of the rest of the list or the last element.
		#/method/ doesn't need to check for the end of the list. It just specifies how to combine any two elements into one.
		#For example, method = "def(u,v) u+v" would make list_reduce behave equivalent to sum(list), albeit slower.
		name: "list_reduce",
		args: "list, method",
		formula: "if(size(list) > 0, if(size(list) > 1, method(list[0], list_reduce(list[1:size(list)], method)), list[0]))",
	},
    {
        name: "foldr",
        args: "f,z,x",
        formula: "if(size(x)=0,z,f(x.first,foldr(f,z,x[1:])))",
    },
    
	{
		name: "head",
		args: "list",
		formula: "if(size(list), list[0])",
	},
	{
		name: "tail",
		args: "list",
		formula: "if(size(list), list[1:size(list)], [])",
	},
	{
		name: "last",
		args: "list",
		formula: "if(size(list), list[size(list)-1])",
	},
	
	{
		name: "unique",
		args: "list",
		formula: "filter(items, index = size(items)-1 or items[index] != items[index+1]) where items = sort(list)",
	},
	
	{
		name: "_find_index",
		args: "list, target, index",
		formula: "
			if(index < size(list),
				if(list[index] = target, 
					index, 
					_find_index(list, target, index+1)),
				null)",
	},
	
	{
		name: "find_index",
		args: "list, target",
		formula: "_find_index(list, target, 0)",
	},
	
	{
		name: "dump",
		args: "toDump",
		formula: "debug_fn(toDump, toDump)",
	},
	{
		name: "dump2",
		args: "id, toDump",
		formula: "if(not id, 
			debug_fn(toDump, toDump),
			debug_fn([id, toDump], toDump))",
	},
	
	{
		name: "set_mid",
		args: "obj, point",
		formula: "debug_fn('Warning: Set_mid is deprecated in favour of object.mid_xy.', if(is_list(point),
			[set(obj.midpoint_x, point[0]), set(obj.midpoint_y, point[1])],
			[set(obj.midpoint_x, point.midpoint_x), set(obj.midpoint_y, point.midpoint_y)]))",
	},
	{
		name: "get_mid",
		args: "obj",
		formula: "debug_fn('Warning: Get_mid is deprecated in favour of object.mid_xy.', 
			[obj.midpoint_x, obj.midpoint_y])",
	},
	
    {
		// left folding algorithm.
		// f -- function to apply, this must be a first-class function, so currently only lambda functions need apply.
		// z -- initial value
		// x -- list to apply the function f to.
		// Examples.
		// inclusive logical or the values in a list of booleans together: 
		//  foldl(def(a,b) a or b, false, [false,false,false,false,false,false,true]) 
		//    --> true
		// Convert a list of maps each having an attribute called id and unqiue values into a map of maps, referenced by id.
		// foldl(def(a,b) a + {b.id:b}, {}, [{id:'a', x:0, y:1}, {id:'b', u:3, v:4}, {id:'c', r:5, s:6}])
		//    --> {'a':{id:'a', x:0, y:1}, 'b':{id:'b', u:3, v:4}, 'c':{id:'c', r:5, s:6}}
        name: "foldl",
        args: "f,z,x",
        formula: "if(size(x)=0,z,foldl(f,f(z,x.first),x[1:]))",
    },
	
	{
		/*
		Args: function, list A, list B, integer or list C
			function: A function to be executed in the context of the current object, taking a list as it's only arg.
				(This will be evaluated on the current frame, but applied over subsequent frames.)
			list A: The initial value to be passed to the function.
			list B: The last value to be passed to the function. Must be same length as list A.
			integer: The number of interpolated frames between list A and list B.
				(The rate of execution is one value/frame.)
			list C: The list produced by range(10) is exactly equivalent to an integer of 10 in this slot.
				(This can give you finer control of the scheduling.)
		Example: scheduled_animation(def(val) [set(self.x, val[0]), set(self.y, val[1])], [5,10], [45,100], 50)
		*/
		name: "scheduled_animation",
		args: "setter, from, to, steps",
		formula: "transform(stepsList, 
			schedule(v, setter(
				list_tween(from, to, 1-decimal(v)/last(stepsList))
				))
			) where stepsList = if(is_list(steps), steps, range(steps))"
	},
	
	{
		name: "newln",
		args: "number",
		formula: "list_cat(transform(range(number), '\n'))",
	},
	
	{
		name: "default", //This provides a convenient wrapper for "if(very_long_variable_name, very_long_variable_name, else_this)"
		args: "input, fallback",
		formula: "if(input, input, fallback)",
	},
	

	"@flatten",
	"@include data/functions-custom.cfg", //Defined in modules.
]