# :scissors: Hair & Beard Coloring
Documentation relating to the **jo_hairdresser_coloring** add-on for the [Hairdresser script](hairdresser).

:::: tabs
::: tab BUY
[Buy the add-on](https://jumpon-studios.com/redm/hair-coloring)
:::

::: tab PREVIEW
<iframe width="560" height="315" src="https://www.youtube.com/embed/L59H6mLFu_Y?si=WpVh0x8uw5KuyYEX" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
:::
::::

## 1. Installation
::: warning
The [Hairdresser script](hairdresser) is required to use this add-on.
:::

To install jo_hairdresser_coloring:
- Drag and drop the resource into your resources folder
  - jo_hairdresser_coloring
- Add this ensure to your server.cfg after `ensure jo_hairdresser`
  - `ensure jo_hairdresser_coloring`

Congratulations, the **Hair & Beard Coloring** add-on is ready to use!

## 2. Usage

:::: tabs
::: tab Open coloring
Go to a hairdresser and select a compatible hair, beard, or hair accessory item.

When the selected item can be colored, the coloring prompt appears in the buy prompt group. Press `C` by default to open the color palette menu.
:::

::: tab Coloring features
In the color palette menu, you can:
- **Choose a palette** - Switch between enabled tint palettes
- **Adjust tints** - Edit the three tint values used by the selected component
- **Preview colors** - See the selected color before buying
- **Buy the color** - Apply and save the colored component through the Hairdresser purchase flow

The add-on supports hair, beard, and hair accessories by default.
:::

::::

## 3. Configuration
The configuration files are located in the `config` folder within the resource. This folder contains two subfolders:

- **`_default.lock/`** - Contains the default configuration files. **Do not edit these files directly** as they may be overwritten during updates.
- **`custom/`** - This is where you place your custom configuration files to override the defaults.

### How to customize the configuration

1. Navigate to `jo_hairdresser_coloring/config/_default.lock/`
2. Copy the file you want to modify (e.g., `prices.lua`)
3. Paste it into `jo_hairdresser_coloring/config/custom/`
4. Edit the copied file in the `custom` folder

The script automatically loads files from `custom/` first, and only uses `_default.lock/` as a fallback. This system ensures your customizations are preserved when updating the script.

### Default configuration files

`jo_hairdresser_coloring/config/_default.lock/global.lua`

```lua
Config.keys = {
	coloring = "INPUT_CREATOR_RS"
}

-- Palette options:
-- enabled (boolean): Show or hide the palette in the menu.
-- disabledTints (table<number>): Tint indices that cannot be selected.
-- min (number): Lowest allowed tint index for the slider.
-- max (number): Highest allowed tint index for the slider.
--
-- Example with disabled tints:
-- tint_makeup = { enabled = true, disabledTints = { 33, 34, 35, 36, 37, 38 } }
--
-- Example with slider bounds:
-- tint_generic_clean = { enabled = true, min = 0, max = 31 }
-- tint_leather = { enabled = true, min = 5, max = 31 }
--
-- Example combining all options:
-- tint_hair = { enabled = true, disabledTints = { 1, 2, 3 }, min = 0, max = 25 }

Config.palettes = {
	hair = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	beards_complete = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	hair_accessories = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	-- =========================================================================
	-- NPC ADDON PALETTES
	-- =========================================================================
	beards = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	beards_chin = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	beards_chops = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	beards_mustache = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
	hair_bonnet = {
		tint_generic_clean = { enabled = true },
		tint_hair = { enabled = true },
		tint_horse = { enabled = true },
		tint_horse_leather = { enabled = true },
		tint_leather = { enabled = true },
		tint_makeup = { enabled = true }
	},
}
```

`jo_hairdresser_coloring/config/_default.lock/lang.lua`

```lua
Lang.coloring = "Coloring"
Lang.customColor = "Custom color"
Lang.noPalette = "You can't access to the coloring"
Lang.palette = "Palette"
Lang.tint = "Tint"
Lang.tint_generic_clean = "Classic"
Lang.tint_hair = "Hair"
Lang.tint_horse = "Horse"
Lang.tint_horse_leather = "Horse leather"
Lang.tint_leather = "Leather"
Lang.tint_makeup = "Makeup"
Lang.tintTitle = "Tint %d"
```

## 4. For developers

### Actions

Actions are one of the two types of Hooks. They provide a way to run a function at a specific point in the execution of scripts. Callback functions for an Action do not return anything back to the calling Action hook. They are the counterpart to Filters.

Below is the available action in the jo_hairdresser_coloring script.

#### `[Client]` Init
Triggered when the add-on links to jo_hairdresser and registers its Hairdresser menu hooks.

```lua
exports.jo_hairdresser_coloring:registerAction('init', function()
    -- Your code here
end)
```

### Filters

[Filters](/DeveloperResources/filters) allow you to modify data or permissions synchronously at specific points in the script. Below is the complete list of `jo_hairdresser_coloring` filters and how to use them.

#### `[Client]` Can open color palette
Control whether the player can open the color palette.

```lua
-- @param canOpen - boolean (default true)
exports.jo_hairdresser_coloring:registerFilter('canOpenColorPalette', function(canOpen)
	return canOpen
end)
```

When the palette is opened from another add-on, the external context is passed as a second argument.

```lua
-- @param canOpen - boolean (default true)
-- @param context - table: external color palette context
exports.jo_hairdresser_coloring:registerFilter('canOpenColorPalette', function(canOpen, context)
	return canOpen
end)
```
