Cube  Diff

Differences From Artifact [892ebc7d62]:

To Artifact [9d395dd08f]:


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
#import "Variable.h"

#include "cube.h"

@implementation Variable




+ (instancetype)variableWithName: (OFString *)name
			     min: (int)min
			     max: (int)max
			 storage: (int *)storage
			function: (void (*__cdecl)())function
		       persisted: (bool)persisted


{
	return [[self alloc] initWithName: name
				      min: min
				      max: max
				  storage: storage
				 function: function
				persisted: persisted];


}

- (instancetype)initWithName: (OFString *)name
			 min: (int)min
			 max: (int)max
		     storage: (int *)storage
		    function: (void (*__cdecl)())function
		   persisted: (bool)persisted


{
	self = [super initWithName: name];

	_min = min;
	_max = max;
	_storage = storage;
	_function = function;
	_persisted = persisted;



	return self;
}

- (void)printValue
{
	conoutf(@"%@ = %d", self.name, *_storage);
}

- (void)setValue: (int)value
{
	bool outOfRange = false;

	if (_min > _max) {





>
>
>
>




<

>
>





<
|
>
>






<

>
>






<

>
>






|







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
#import "Variable.h"

#include "cube.h"

@implementation Variable
{
	int *_storage;
}

+ (instancetype)variableWithName: (OFString *)name
			     min: (int)min
			     max: (int)max
			 storage: (int *)storage

		       persisted: (bool)persisted
			  getter: (int (^)(void))getter
			  setter: (void (^)(int))setter
{
	return [[self alloc] initWithName: name
				      min: min
				      max: max
				  storage: storage

				persisted: persisted
				   getter: getter
				   setter: setter];
}

- (instancetype)initWithName: (OFString *)name
			 min: (int)min
			 max: (int)max
		     storage: (int *)storage

		   persisted: (bool)persisted
		      getter: (int (^)(void))getter
		      setter: (void (^)(int))setter
{
	self = [super initWithName: name];

	_min = min;
	_max = max;
	_storage = storage;

	_persisted = persisted;
	_getter = [getter copy];
	_setter = [setter copy];

	return self;
}

- (void)printValue
{
	conoutf(@"%@ = %d", self.name, self.value);
}

- (void)setValue: (int)value
{
	bool outOfRange = false;

	if (_min > _max) {
56
57
58
59
60
61
62
63
64

65




66
67
68


69
70


71
72
	}

	if (value > _max) {
		value = _max;
		outOfRange = true;
	}

	if (outOfRange)
		conoutf(@"valid range for %@ is %d..%d", self.name, _min, _max);






	*_storage = value;

	if (_function != NULL)


		// call trigger function if available
		_function();


}
@end







|

>
|
>
>
>
>
|
|
|
>
>
|
|
>
>


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
	}

	if (value > _max) {
		value = _max;
		outOfRange = true;
	}

	if (outOfRange) {
		conoutf(@"valid range for %@ is %d..%d", self.name, _min, _max);
		return;
	}

	if (_setter != NULL)
		_setter(value);
	else
		*_storage = value;
}

- (int)value
{
	if (_getter != NULL)
		return _getter();
	else
		return *_storage;
}
@end