Playlist Module
Overview
This script is a module that manages playlists in the game. It provides functionalities to retrieve, play, and search for playlists. It integrates with both the Tracks and Sound modules to fetch track details and control sound playback, respectively.
Data Structures
playlists: A table that contains predefined playlists. Each playlist has anid,name,image, and a list oftracks.
Events
Selected: Triggered when a playlist is selected.
Functions
Playlists.GetPlaylists():Description: Retrieves all available playlists.
Returns: A table containing all playlists.
Playlists.GetPlaylist(id):Description: Retrieves a specific playlist by its ID.
Parameters:
id(string): The ID of the desired playlist.
Returns: The details of the specified playlist.
Playlists.Play(playlistId):Description: Sets a specific playlist as active.
Parameters:
playlistId(string): The ID of the playlist to set as active.
Playlists.GetActive():Description: Retrieves the currently active playlist.
Returns: The details of the active playlist.
Playlists.GetFirstTrack():Description: Retrieves the first track of the active playlist.
Returns: The ID of the first track in the active playlist.
Playlists.GetNextTrack():Description: Retrieves the next track in the active playlist.
Returns: The ID of the next track in the active playlist.
Playlists.GetTracks(id):Description: Retrieves all tracks from the active playlist.
Parameters:
id(string): The ID of the desired playlist.
Returns: A table containing all tracks in the specified playlist.
Playlists.search(title, artist):Description: Searches for playlists based on title and artist.
Parameters:
title(string): The title of the track.artist(string): The artist of the track.
Returns: A table containing playlists that match the search criteria.
Utility Functions
levenshteinDistance(str1, str2):Description: Calculates the Levenshtein distance between two strings.
Parameters:
str1(string): The first string.str2(string): The second string.
Returns: The Levenshtein distance between the two strings.
advancedSearch(tbl, kvs):Description: Searches for exact matches in a table based on key-value pairs.
Parameters:
tbl(table): The table to search in.kvs(table): The key-value pairs to search for.
Returns: The rows in the table that match the search criteria.
fuzzySearch(tbl, kvs, threshold):Description: Searches for approximate matches in a table based on key-value pairs and a threshold.
Parameters:
tbl(table): The table to search in.kvs(table): The key-value pairs to search for.threshold(number): The maximum Levenshtein distance for a match.
Returns: The rows in the table that match the search criteria.
Notes
The
Playlistsmodule provides a comprehensive set of functionalities to manage playlists in the game, making it easier for developers to integrate playlist-related features.The utility functions, especially
levenshteinDistance,advancedSearch, andfuzzySearch, are general-purpose and can be moved to a common library for reuse across different modules.
Last updated