MediaWiki:Gadget-calc-cooking.js

From Idle Clans wiki
Revision as of 19:28, 10 June 2024 by Uraxys (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(function () {
	var CLAN_HOUSES = ["Tent", "Barn", "Windmill", "House", "Manor", "Castle"];
	var PERSONAL_HOUSES = ["Cardboard box", "Tent", "Van Down by the River", "Small cabin", "House"];
	var SKILL_CAPE = ["None", "Tier 1", "Tier 2", "Tier 3", "Tier 4"];
	var ENCHANTMENTS = ["None", "Common", "Rare", "Exceptional"];

	var utils = idleClans.util;
	var data = idleClans.data;

	function addDropdown($element, $dropdown, title, alignment) {
		alignment = alignment || "left";

		$element.append("<div class='calc-label-" + alignment + "'>" + title + "</div>");
		$element.append($dropdown.$element);
	}

	function addHeader($element, title) {
		$element.append("<div class='calc-header'>" + title + "</div>");
	}

	function addResultEntry($element, label, $result) {
		var $entry = $("<div class='calc-result-entry'></div>");
		$entry.append($("<div class='label'><span>" + label + "</span></div>"), $result);
		var $value = $("<div class='value'></div>");
		$value.append($result);
		$entry.append($value);

		$element.append($entry);
	}

	function addResultSpacer($element) {
		$element.append("<div class='calc-result-spacer'></div>");
	}

	function getDropdownValue($dropdown) {
		return $dropdown.getMenu().findSelectedItem().getData();
	}

	function createCalculator($element) {
		$element.addClass("idle-calculator");

		// XP
		var $clanHouseDropdown = utils.ui.dropdown(utils.tierify(CLAN_HOUSES, "None"), 0);
		var $personalHouseDropdown = utils.ui.dropdown(utils.tierify(PERSONAL_HOUSES, "None"), 0);
		var $dailyAdDropdown = utils.ui.dropdown(["None", "30%", "24/7 (10%)"], 0);

		// Speed
		var skillingItemOptions = utils.tierify(
			[ function(i) {return utils.getRefinedName("cooking pan", i)}, 7 ],
			"None");
		var $skillItemDropdown = utils.ui.dropdown(skillingItemOptions, 0);
		var $skillCapeDropdown = utils.ui.dropdown(SKILL_CAPE, 0);
		// - Enchantments
		var $amuletDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $earringDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $ringDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $braceletDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $poakDropdown = utils.ui.dropdown(["No", "Yes"], 0);

		// Task
		var taskOptions = idleClans.data.tasks.COOKING.map(function (task) {
			return task.name;
		});
		// Add "Salect task" as the first option.
		taskOptions.splice(15, 0, {label: "==== Dishes ====", header: true});
		taskOptions.splice(11, 0, {label: "==== Meat ====", header: true});
		taskOptions.splice(0, 0, {label: "==== Fish ====", header: true});
		var $taskDropdown = utils.ui.dropdown(taskOptions, undefined, "S\u0065lect task");
		// Button
		var $calculateButton = utils.ui.buttonInput("Calculate");
		// - Disable the button if no task is selected.
		if ($taskDropdown.getMenu().findSelectedItem() === null)
			$calculateButton.setDisabled(true);
		// - Enable the button if a task is selected.
		$taskDropdown.on("labelChange", function () {
			$calculateButton.setDisabled(false);
		});

		// Add the elements to the calculator.

		$element.append("<div class='calc-title'>Cooking Calculator</div>");
		var $settings = $("<div class='calc-category'></div>");

		// - Xp

		addHeader($settings, "Upgrades & Boosts");
		addDropdown($settings, $clanHouseDropdown, "Clan House");
		addDropdown($settings, $personalHouseDropdown, "Personal House");
		addDropdown($settings, $dailyAdDropdown, "Daily Ad");

		// - Speed

		addHeader($settings, "Equipment");
		addDropdown($settings, $skillItemDropdown, "Skilling Item");
		addDropdown($settings, $skillCapeDropdown, "Skill Cape");

		// - Enchantments

		addHeader($settings, "Enchantments");
		var $enchantments = $("<div class='calc-enchantments'></div>");
		var $enchantmentsContainerL = $("<div class='calc-enchantments-container'></div>");
		var $enchantmentsContainerR = $("<div class='calc-enchantments-container'></div>");

		$enchantmentsContainerL.append("<div class='calc-label-center'>Amulet</div>", $amuletDropdown.$element);
		$enchantmentsContainerL.append("<div class='calc-label-center'>Ring</div>", $ringDropdown.$element);
		$enchantmentsContainerR.append("<div class='calc-label-center'>Earring</div>", $earringDropdown.$element);
		$enchantmentsContainerR.append("<div class='calc-label-center'>Bracelet</div>", $braceletDropdown.$element);
		$enchantments.append($enchantmentsContainerL);
		$enchantments.append($enchantmentsContainerR);
		$settings.append($enchantments);
		addDropdown($settings, $poakDropdown, "Potion of Ancient Knowledge", "center")

		$element.append($settings);

		// Task

		var $task = $("<div class='calc-category calc-plain-category' style='margin-top: 0.5rem;margin-bottom: 0.5rem'></div>");
		addDropdown($task, $taskDropdown, "Task");
		var $buttonDiv = $("<div class='calc-button'></div>");
		$buttonDiv.append($calculateButton.$element);
		$task.append($buttonDiv);
		$element.append($task);

		// Result

		var $results = $("<div class='calc-result'></div>");
		var $xpPerTaskResult = $("<span>???</span>");
		var $timePerTaskResult = $("<span>???</span>");
		var $xpPerHourResult = $("<span>???</span>");
		var $tasksPerHourResult = $("<span>???</span>");