Cube  Diff

Differences From Artifact [1956763843]:

To Artifact [254356cb16]:


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
	OFMutableArray<OFString *> *copy;

	if (arguments.count >= count)
		return arguments;

	copy = [arguments mutableCopy];
	while (copy.count < count)
		[copy addObject:@""];

	[copy makeImmutable];
	return copy;
}

@implementation Command
{
	id _block;
}

+ (instancetype)commandWithName:(OFString *)name
                 argumentsTypes:(int)argumentsTypes
                          block:(id)block
{
	return [[self alloc] initWithName:name
	                   argumentsTypes:argumentsTypes
	                            block:block];
}

- (instancetype)initWithName:(OFString *)name
              argumentsTypes:(int)argumentsTypes
                       block:(id)block
{
	self = [super initWithName:name];

	_argumentsTypes = argumentsTypes;
	_block = block;

	return self;
}

- (int)callWithArguments:(OFArray<OFString *> *)arguments isDown:(bool)isDown
{
	switch (_argumentsTypes) {
	case ARG_1INT:
		if (isDown) {
			arguments = padArguments(arguments, 2);
			((void (^)(int))_block)(
			    [arguments[1] cube_intValueWithBase:0]);
		}
		break;
	case ARG_2INT:
		if (isDown) {
			arguments = padArguments(arguments, 3);
			((void (^)(int, int))_block)(
			    [arguments[1] cube_intValueWithBase:0],
			    [arguments[2] cube_intValueWithBase:0]);
		}
		break;
	case ARG_3INT:
		if (isDown) {
			arguments = padArguments(arguments, 4);
			((void (^)(int, int, int))_block)(
			    [arguments[1] cube_intValueWithBase:0],
			    [arguments[2] cube_intValueWithBase:0],
			    [arguments[3] cube_intValueWithBase:0]);
		}
		break;
	case ARG_4INT:
		if (isDown) {
			arguments = padArguments(arguments, 5);
			((void (^)(int, int, int, int))_block)(
			    [arguments[1] cube_intValueWithBase:0],
			    [arguments[2] cube_intValueWithBase:0],
			    [arguments[3] cube_intValueWithBase:0],
			    [arguments[4] cube_intValueWithBase:0]);
		}
		break;
	case ARG_NONE:
		if (isDown)
			((void (^)())_block)();
		break;
	case ARG_1STR:







|










|
|
|

|
|
|


|
|
|

|







|






|






|
|






|
|
|






|
|
|
|







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
	OFMutableArray<OFString *> *copy;

	if (arguments.count >= count)
		return arguments;

	copy = [arguments mutableCopy];
	while (copy.count < count)
		[copy addObject: @""];

	[copy makeImmutable];
	return copy;
}

@implementation Command
{
	id _block;
}

+ (instancetype)commandWithName: (OFString *)name
                 argumentsTypes: (int)argumentsTypes
                          block: (id)block
{
	return [[self alloc] initWithName: name
	                   argumentsTypes: argumentsTypes
	                            block: block];
}

- (instancetype)initWithName: (OFString *)name
              argumentsTypes: (int)argumentsTypes
                       block: (id)block
{
	self = [super initWithName: name];

	_argumentsTypes = argumentsTypes;
	_block = block;

	return self;
}

- (int)callWithArguments: (OFArray<OFString *> *)arguments isDown: (bool)isDown
{
	switch (_argumentsTypes) {
	case ARG_1INT:
		if (isDown) {
			arguments = padArguments(arguments, 2);
			((void (^)(int))_block)(
			    [arguments[1] cube_intValueWithBase: 0]);
		}
		break;
	case ARG_2INT:
		if (isDown) {
			arguments = padArguments(arguments, 3);
			((void (^)(int, int))_block)(
			    [arguments[1] cube_intValueWithBase: 0],
			    [arguments[2] cube_intValueWithBase: 0]);
		}
		break;
	case ARG_3INT:
		if (isDown) {
			arguments = padArguments(arguments, 4);
			((void (^)(int, int, int))_block)(
			    [arguments[1] cube_intValueWithBase: 0],
			    [arguments[2] cube_intValueWithBase: 0],
			    [arguments[3] cube_intValueWithBase: 0]);
		}
		break;
	case ARG_4INT:
		if (isDown) {
			arguments = padArguments(arguments, 5);
			((void (^)(int, int, int, int))_block)(
			    [arguments[1] cube_intValueWithBase: 0],
			    [arguments[2] cube_intValueWithBase: 0],
			    [arguments[3] cube_intValueWithBase: 0],
			    [arguments[4] cube_intValueWithBase: 0]);
		}
		break;
	case ARG_NONE:
		if (isDown)
			((void (^)())_block)();
		break;
	case ARG_1STR:
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
			    arguments[1], arguments[2]);
		}
		break;
	case ARG_VARI:
		if (isDown)
			// limit, remove
			((void (^)(OFString *))_block)([[arguments
			    objectsInRange:OFMakeRange(1, arguments.count - 1)]
			    componentsJoinedByString:@" "]);
		break;
	}

	return 0;
}
@end







|
|






150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
			    arguments[1], arguments[2]);
		}
		break;
	case ARG_VARI:
		if (isDown)
			// limit, remove
			((void (^)(OFString *))_block)([[arguments
			    objectsInRange: OFMakeRange(1, arguments.count - 1)]
			    componentsJoinedByString: @" "]);
		break;
	}

	return 0;
}
@end