Cube  Diff

Differences From Artifact [ea51019800]:

To Artifact [20418af9a4]:


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
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







+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
-
+
-
-
+
+
+
+
+
+




-
+

-
-
-
-
+
+
+
-
-
-
+


-

+
+







		draw_text(refs[j], FONTH / 3,
		    (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);
	};
};

// keymap is defined externally in keymap.cfg

@interface KeyMapping : OFObject
@property (readonly) int code;
@property (readonly, nonatomic) OFString *name;
@property (copy, nonatomic) OFString *action;
struct keym {
	int code;
	char *name;
	char *action;
} keyms[256];
int numkm = 0;

- (instancetype)initWithCode:(int)code name:(OFString *)name;
@end

@implementation KeyMapping
- (instancetype)initWithCode:(int)code name:(OFString *)name
{
	self = [super init];

	_code = code;
	_name = [name copy];

	return self;
}
@end

static OFMutableArray<KeyMapping *> *keyMappings = nil;

void
keymap(OFString *code, OFString *key, OFString *action)
{
	@autoreleasepool {
		keyms[numkm].code = (int)code.longLongValue;
		keyms[numkm].name = newstring(key.UTF8String);
	if (keyMappings == nil)
		keyms[numkm++].action = newstringbuf(action.UTF8String);
	}
		keyMappings = [[OFMutableArray alloc] init];

	KeyMapping *mapping =
	    [[KeyMapping alloc] initWithCode:(int)code.longLongValue name:key];
	mapping.action = action;
	[keyMappings addObject:mapping];
}
COMMAND(keymap, ARG_3STR)

void
bindkey(OFString *key_, OFString *action)
bindkey(OFString *key, OFString *action)
{
	@autoreleasepool {
		std::unique_ptr<char> key(strdup(key_.UTF8String));
		for (char *x = key.get(); *x; x++)
			*x = toupper(*x);
	for (KeyMapping *mapping in keyMappings) {
		if ([mapping.name caseInsensitiveCompare:key] ==
		    OFOrderedSame) {
		loopi(numkm) if (strcmp(keyms[i].name, key.get()) == 0)
		{
			strcpy_s(keyms[i].action, action.UTF8String);
			mapping.action = action;
			return;
		}
		conoutf(@"unknown key \"%s\"", key.get());
	}

	conoutf(@"unknown key \"%@\"", key);
}
COMMANDN(bind, bindkey, ARG_2STR)

void
saycommand(char *init) // turns input to the command line on or off
{
	saycommandon = (init != NULL);
240
241
242
243
244
245
246
247
248
249
250
251







252
253
254
255
256




257
258
259




260
261
262
263
264
265
266


267
268

269
270

271
272
273
274



275
276

255
256
257
258
259
260
261





262
263
264
265
266
267
268





269
270
271
272



273
274
275
276
277
278
279
280
281


282
283
284

285
286

287




288
289
290


291







-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+





-
-
+
+

-
+

-
+
-
-
-
-
+
+
+
-
-
+
						toserver(commandbuf);
				};
				saycommand(NULL);
			} else if (code == SDLK_ESCAPE) {
				saycommand(NULL);
			};
		};
	} else if (!menukey(code, isdown)) // keystrokes go to menu
	{
		loopi(numkm) if (keyms[i].code ==
		                 code) // keystrokes go to game, lookup in
		                       // keymap and execute
	} else if (!menukey(code, isdown)) {
		// keystrokes go to menu

		for (KeyMapping *mapping in keyMappings) {
			if (mapping.code == code) {
				// keystrokes go to game, lookup in keymap and
				// execute
		{
			string temp;
			strcpy_s(temp, keyms[i].action);
			execute(temp, isdown);
			return;
				string temp;
				strcpy_s(temp, mapping.action.UTF8String);
				execute(temp, isdown);
				return;
		};
	};
};
			}
		}
	}
}

char *
getcurcommand()
{
	return saycommandon ? commandbuf : NULL;
};

}

void
writebinds(FILE *f)
writebinds(OFStream *stream)
{
	loopi(numkm)
	for (KeyMapping *mapping in keyMappings)
	{
		if (*keyms[i].action)
			fprintf(f, "bind \"%s\" [%s]\n", keyms[i].name,
			    keyms[i].action);
		if (mapping.action.length > 0)
			[stream writeFormat:@"bind \"%@\" [%@]\n", mapping.name,
			        mapping.action];
	};
};
}