<commit_before>part of couclient;

class MenuOption {
	String uiName, serverName, errorText, itemType;
	int timeRequired;
	bool enabled;
	Map dropMap;
}

class RightClickMenu {
	static final String
		ACTION_LIST_PARENT_ID = 'RCActionList',
		MENU_CLASS = 'RightClickMenu',
		MENU_INFO_CLASSES = 'InfoButton fa fa-info-circle',
		MENU_TITLE_ID = 'ClickTitle',
		MENU_VISIBLE_OPACITY = '1.0',
		OPTION_BUTTON_CLASS = 'RCItem',
		OPTION_DISABLED_CLASS = 'RCItemDisabled',
		OPTION_SELECTED_CLASS = 'RCItemSelected',
		OPTION_TOOLTIP_CLASS = 'action_error_tooltip',
		OPTION_WRAPPER_CLASS = 'action_wrapper';

	static Element create3(
		MouseEvent click, String title, String entityId,
		{String serverClass, String description, List<Action> actions, Function onInfo, ItemDef item, String itemName}
	) {
		Point<int> _positionMenu(DivElement menu) {
			int x, y;

			if (click != null) {
				// Position at cursor

				x = click.client.x - (menu.clientWidth ~/ 2);
				y = click.client.y - (40 + (actions.length * 30));
			} else {
				// Position at player

				num playerX = CurrentPlayer.left,
					playerY = CurrentPlayer.top;

				int playerWidth = CurrentPlayer.width,
					playerHeight = CurrentPlayer.height;

				num translateX = playerX,
					translateY = view.worldElement.clientHeight - playerHeight;

				int streetWidth = currentStreet.bounds.width,
					streetHeight = currentStreet.bounds.height;

				int worldHeight = view.worldElement.clientHeight,
					worldWidth = view.worldElement.clientWidth;

				if (playerX > streetWidth - playerWidth / 2 - worldWidth / 2) {
					translateX = playerX - streetWidth + worldWidth;
				} else if (playerX + playerWidth / 2 > worldWidth / 2) {
					translateX = worldWidth / 2 - playerWidth / 2;
				}

				if (playerY + playerHeight / 2 < worldHeight / 2) {
					translateY = playerY;
				} else if (playerY < streetHeight - playerHeight / 2 - worldHeight / 2) {
					translateY = worldHeight / 2 - playerHeight / 2;
				} else {
					translateY = worldHeight - (streetHeight - playerY);
				}

				x = (translateX + menu.clientWidth + 10) ~/ 1;
				y = (translateY + playerHeight / 2) ~/ 1;
			}

			return new Point(x, y);
		}

		List<Element> _makeOptions(DivElement menu) {
			List<Element> options = [];

			// Keyboard selection
			bool useKeys = (actions.length <= 10);
			int keyIndex = 1;

			// Create option elements
			for (Action action in actions) {
				// Option tooltip
				DivElement optionTooltip = new DivElement()
					..classes = [OPTION_TOOLTIP_CLASS];

				// Option button
				DivElement option = new DivElement()
					..classes = [OPTION_BUTTON_CLASS]
					..text = (useKeys ? '$keyIndex: ' : '') + action.actionName;

				// Option element wrapper (option + tooltip)
				DivElement optionWrapper = new DivElement()
					..classes = [OPTION_WRAPPER_CLASS]
					..append(option)
					..append(optionTooltip);

				// Register keyboard shortcut listener
				if (useKeys) {
					MenuKeys.addListener(keyIndex, () {
						// When this option's number key pressed
						if (click != null) {
							// Recreate mouse click
							option.dispatchEvent(new MouseEvent(
								'click', clientX: click.client.x, clientY: click.client.y));
						} else {
							// Simulate mouse click
							option.click();
						}
					});
				}

				if (action.enabled) {
					// Attach click listeners to enabled actions
					option.onClick.listen((MouseEvent event) async {
						String functionName = action.actionName.toLowerCase();

						Function doClick = ({int howMany: 1}) async {
							bool completed = true;

							// Wait for actions to complete
							if (action.timeRequired > 0) {
								ActionBubble actionBubble = new ActionBubble.withAction(action);
								completed = await actionBubble.wait;
							}

							if (completed) {
								// Action completed
								Map<String, dynamic> arguments = {};

								// Accepts multiple items
								if (action.dropMap != null) {
									arguments = action.dropMap;
									arguments['count'] = howMany;
								}

								if (functionName == 'pickup' && howMany > 1) {
									// Picking up multiple items
									List<String> objects = CurrentPlayer.intersectingObjects.keys.toList();
									objects.removeWhere((String id) {
										return (querySelector('#$id').attributes['name'] != (itemName ?? item.name));
									});
									arguments['pickupIds'] = objects;
									sendGlobalAction(functionName, arguments);
								} else if (serverClass == "global_action_monster") {
									sendGlobalAction(functionName, {"player": entityId});
								} else {
									// Other action
									if (item != null) {
										arguments['itemdata'] = item.metadata;
									}

									sendAction(functionName, entityId, arguments);
								}
							}
						};

						if (action.multiEnabled) {<commit_msg>don't try to perform item actions on ground entities (like stills)<commit_after>part of couclient;

class MenuOption {
	String uiName, serverName, errorText, itemType;
	int timeRequired;
	bool enabled;
	Map dropMap;
}

class RightClickMenu {
	static final String
		ACTION_LIST_PARENT_ID = 'RCActionList',
		MENU_CLASS = 'RightClickMenu',
		MENU_INFO_CLASSES = 'InfoButton fa fa-info-circle',
		MENU_TITLE_ID = 'ClickTitle',
		MENU_VISIBLE_OPACITY = '1.0',
		OPTION_BUTTON_CLASS = 'RCItem',
		OPTION_DISABLED_CLASS = 'RCItemDisabled',
		OPTION_SELECTED_CLASS = 'RCItemSelected',
		OPTION_TOOLTIP_CLASS = 'action_error_tooltip',
		OPTION_WRAPPER_CLASS = 'action_wrapper';

	static Element create3(
		MouseEvent click, String title, String entityId,
		{String serverClass, String description, List<Action> actions, Function onInfo, ItemDef item, String itemName}
	) {
		Point<int> _positionMenu(DivElement menu) {
			int x, y;

			if (click != null) {
				// Position at cursor

				x = click.client.x - (menu.clientWidth ~/ 2);
				y = click.client.y - (40 + (actions.length * 30));
			} else {
				// Position at player

				num playerX = CurrentPlayer.left,
					playerY = CurrentPlayer.top;

				int playerWidth = CurrentPlayer.width,
					playerHeight = CurrentPlayer.height;

				num translateX = playerX,
					translateY = view.worldElement.clientHeight - playerHeight;

				int streetWidth = currentStreet.bounds.width,
					streetHeight = currentStreet.bounds.height;

				int worldHeight = view.worldElement.clientHeight,
					worldWidth = view.worldElement.clientWidth;

				if (playerX > streetWidth - playerWidth / 2 - worldWidth / 2) {
					translateX = playerX - streetWidth + worldWidth;
				} else if (playerX + playerWidth / 2 > worldWidth / 2) {
					translateX = worldWidth / 2 - playerWidth / 2;
				}

				if (playerY + playerHeight / 2 < worldHeight / 2) {
					translateY = playerY;
				} else if (playerY < streetHeight - playerHeight / 2 - worldHeight / 2) {
					translateY = worldHeight / 2 - playerHeight / 2;
				} else {
					translateY = worldHeight - (streetHeight - playerY);
				}

				x = (translateX + menu.clientWidth + 10) ~/ 1;
				y = (translateY + playerHeight / 2) ~/ 1;
			}

			return new Point(x, y);
		}

		List<Element> _makeOptions(DivElement menu) {
			List<Element> options = [];

			// Keyboard selection
			bool useKeys = (actions.length <= 10);
			int keyIndex = 1;

			// Create option elements
			for (Action action in actions) {
				// Option tooltip
				DivElement optionTooltip = new DivElement()
					..classes = [OPTION_TOOLTIP_CLASS];

				// Option button
				DivElement option = new DivElement()
					..classes = [OPTION_BUTTON_CLASS]
					..text = (useKeys ? '$keyIndex: ' : '') + action.actionName;

				// Option element wrapper (option + tooltip)
				DivElement optionWrapper = new DivElement()
					..classes = [OPTION_WRAPPER_CLASS]
					..append(option)
					..append(optionTooltip);

				// Register keyboard shortcut listener
				if (useKeys) {
					MenuKeys.addListener(keyIndex, () {
						// When this option's number key pressed
						if (click != null) {
							// Recreate mouse click
							option.dispatchEvent(new MouseEvent(
								'click', clientX: click.client.x, clientY: click.client.y));
						} else {
							// Simulate mouse click
							option.click();
						}
					});
				}

				if (action.enabled) {
					// Attach click listeners to enabled actions
					option.onClick.listen((MouseEvent event) async {
						String functionName = action.actionName.toLowerCase();

						Function doClick = ({int howMany: 1}) async {
							bool completed = true;

							// Wait for actions to complete
							if (action.timeRequired > 0) {
								ActionBubble actionBubble = new ActionBubble.withAction(action);
								completed = await actionBubble.wait;
							}

							if (completed) {
								// Action completed
								Map<String, dynamic> arguments = {};

								// Accepts multiple items
								if (action.dropMap != null) {
									arguments = action.dropMap;
									arguments['count'] = howMany;
								}

								if (functionName == 'pickup' && howMany > 1) {
									// Picking up multiple items
									List<String> objects = CurrentPlayer.intersectingObjects.keys.toList();
									objects.removeWhere((String id) {
										return (querySelector('#$id').attributes['name'] != (itemName ?? item.name));
									});
									arguments['pickupIds'] = objects;
									sendGlobalAction(functionName, arguments);
								} else if (serverClass == "global_action_monster") {
									sendGlobalAction(functionName, {"player": entityId});
								} else {
									// Other action
									if (item != null) {
										arguments['itemdata'] = item.metadata;
									}

									sendAction(functionName, entityId, arguments);
								}
							}
						};

						if (item != null && action.multiEnabled) {
{'fraction_non_alphanumeric': 0.11238838140203222, 'fraction_numerical': 0.006363543056553423, 'mean_word_length': 2.6535433070866143, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3308185', 'n_tokens_mistral': 3962, 'n_tokens_neox': 2845, 'n_words': 734}