Просмотр исходного кода

moved mods_list.sh functions to core

UltimateByte 9 лет назад
Родитель
Сommit
609b346b9a
1 измененных файлов с 200 добавлено и 0 удалено
  1. 200 0
      lgsm/functions/mods_core.sh

+ 200 - 0
lgsm/functions/mods_core.sh

@@ -17,6 +17,16 @@ modsdatadir="${lgsmdir}/data/mods"
 modslockfile="installed-mods-listing"
 modslockfilefullpath="${modsdatadir}/${modslockfile}"
 
+# Sets some gsm requirements
+fn_gsm_requirements(){
+	# If tmpdir variable doesn't exist, LGSM is too old
+	if [ -z "${tmpdir}" ]||[ -z "${lgsmdir}" ]; then
+		fn_print_fail "Your LGSM version is too old."
+		echo " * Please do a full update, including ${selfname} script."
+		core_exit.sh
+	fi
+}
+
 # Create mods directory if it doesn't exist
 # Assuming the game is already installed as mods_list.sh checked for it.
 fn_mods_dir(){
@@ -216,3 +226,193 @@ fn_postinstall_tasks(){
 	done
 	fn_print_ok "Rearranging ${modcommand}-files.list"
 }
+
+## mods_list.sh arrays
+
+# Define all variables from a mod at once when index is set to a separator
+fn_mod_info(){
+# If for some reason no index is set, none of this can work
+if [ -z "$index" ]; then
+	fn_print_error "index variable not set. Please report an issue to LGSM Team."
+	echo "* https://github.com/GameServerManagers/LinuxGSM/issues"
+	core_exit.sh
+fi
+	modcommand="${mods_global_array[index+1]}"
+	modprettyname="${mods_global_array[index+2]}"
+	modurl="${mods_global_array[index+3]}"
+	modfilename="${mods_global_array[index+4]}"
+	modsubdirs="${mods_global_array[index+5]}"
+	modlowercase="${mods_global_array[index+6]}"
+	modinstalldir="${mods_global_array[index+7]}"
+	modkeepfiles="${mods_global_array[index+8]}"
+	modengines="${mods_global_array[index+9]}"
+	modgames="${mods_global_array[index+10]}"
+	modexcludegames="${mods_global_array[index+11]}"
+	modsite="${mods_global_array[index+12]}"
+	moddescription="${mods_global_array[index+13]}"
+}
+
+
+# Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable
+fn_compatible_mod_games(){
+	# Reset test value
+	modcompatiblegame="0"
+	# If value is set to GAMES (ignore)
+	if [ "${modgames}" != "GAMES" ]; then
+		# How many games we need to test
+		gamesamount="$(echo "${modgames}" | awk -F ';' '{ print NF }')"
+		# Test all subvalue of "modgames" using the ";" separator
+		for ((gamevarindex=1; gamevarindex < ${gamesamount}; gamevarindex++)); do
+			# Put current game name into modtest variable
+			gamemodtest="$( echo "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
+			# If game name matches
+			if [ "${gamemodtest}" == "${gamename}" ]; then
+				# Mod is compatible !
+				modcompatiblegame="1"
+			fi
+		done
+	fi
+}
+
+# Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable
+fn_compatible_mod_engines(){
+	# Reset test value
+	modcompatibleengine="0"
+	# If value is set to ENGINES (ignore)
+	if [ "${modengines}" != "ENGINES" ]; then
+		# How many engines we need to test
+		enginesamount="$(echo "${modengines}" | awk -F ';' '{ print NF }')"
+		# Test all subvalue of "modengines" using the ";" separator
+		for ((gamevarindex=1; gamevarindex < ${enginesamount}; gamevarindex++)); do
+			# Put current engine name into modtest variable
+			enginemodtest="$( echo "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
+			# If engine name matches
+			if [ "${enginemodtest}" == "${engine}" ]; then
+				# Mod is compatible !
+				modcompatibleengine="1"
+			fi
+		done
+	fi
+}
+
+# Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable
+fn_not_compatible_mod_games(){
+	# Reset test value
+	modeincompatiblegame="0"
+	# If value is set to NOTGAMES (ignore)
+	if [ "${modexcludegames}" != "NOTGAMES" ]; then
+		# How many engines we need to test
+		excludegamesamount="$(echo "${modexcludegames}" | awk -F ';' '{ print NF }')"
+		# Test all subvalue of "modexcludegames" using the ";" separator
+		for ((gamevarindex=1; gamevarindex < ${excludegamesamount}; gamevarindex++)); do
+			# Put current engine name into modtest variable
+			excludegamemodtest="$( echo "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
+			# If engine name matches
+			if [ "${excludegamemodtest}" == "${gamename}" ]; then
+				# Mod is compatible !
+				modeincompatiblegame="1"
+			fi
+		done
+	fi
+}
+
+# Sums up if a mod is compatible or not with modcompatibility=0/1
+fn_mod_compatible_test(){
+	# Test game and engine compatibility
+	fn_compatible_mod_games
+	fn_compatible_mod_engines
+	fn_not_compatible_mod_games
+	if [ "${modeincompatiblegame}" == "1" ]; then
+		modcompatibility="0"
+	elif [ "${modcompatibleengine}" == "1" ]||[ "${modcompatiblegame}" == "1" ]; then
+		modcompatibility="1"
+	else
+		modcompatibility="0"
+	fi
+}
+
+# Checks if a mod is compatibile for installation
+# Provides available mods for installation
+# Provides commands for mods installation
+fn_mods_available(){
+	# First, reset variables
+	compatiblemodslist=()
+	availablemodscommands=()
+	modprettynamemaxlength="0"
+	modsitemaxlength="0"
+	moddescriptionmaxlength="0"
+	modcommandmaxlength="0"
+	# Find compatible games
+	# Find separators through the global array
+	for ((index="0"; index <= ${#mods_global_array[@]}; index++)); do
+		# If current value is a separator; then
+		if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
+			# Set mod variables
+			fn_mod_info
+			# Test if game is compatible
+			fn_mod_compatible_test
+			# If game is compatible
+			if [ "${modcompatibility}" == "1" ]; then
+				# Put it into an array to prepare user output
+				compatiblemodslist+=( "${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}" )
+				# Keep available commands in an array to make life easier
+				availablemodscommands+=( "${modcommand}" )
+			fi
+		fi
+	done
+}
+
+# Output available mods in a nice way to the user
+fn_mods_show_available(){
+	# Set and reset vars
+	compatiblemodslistindex=0
+	spaces=" "
+	# As long as we're within index values
+	while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
+		# Set values for convenience
+		displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
+		displayedmodcommand="${compatiblemodslist[compatiblemodslistindex+1]}"
+		displayedmodsite="${compatiblemodslist[compatiblemodslistindex+2]}"
+		displayedmoddescription="${compatiblemodslist[compatiblemodslistindex+3]}"
+		# Output mods to the user
+		echo -e "\e[1m${displayedmodname}\e[0m - ${displayedmoddescription} - ${displayedmodsite}"
+		echo -e " * \e[36m${displayedmodcommand}\e[0m"
+		# Increment index from the amount of values we just displayed
+		let "compatiblemodslistindex+=4"
+	done
+	# If no mods are found
+	if [ -z "${compatiblemodslist}" ]; then
+		fn_print_fail "No mods are currently available for ${gamename}."
+		core_exit.sh
+	fi
+}
+
+# Get details of a mod any (relevant and unique, such as full mod name or install command) value
+fn_mod_get_info_from_command(){
+	# Variable to know when job is done
+	modinfocommand="0"
+	# Find entry in global array
+	for ((index=0; index <= ${#mods_global_array[@]}; index++)); do
+		# When entry is found
+		if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
+			# Go back to the previous "MOD" separator
+			for ((index=index; index <= ${#mods_global_array[@]}; index--)); do
+				# When "MOD" is found
+				if [ "${mods_global_array[index]}" == "MOD" ]; then
+					# Get info
+					fn_mod_info
+					modinfocommand="1"
+					break
+				fi
+			done
+		fi
+		# Exit the loop if job is done
+		if [ "${modinfocommand}" == "1" ]; then
+			break
+		fi
+	done
+}
+
+fn_gsm_requirements
+fn_mods_info
+fn_mods_available