Archived
Private
Public Access
1
0

Update 29.10.2022

This commit is contained in:
2022-10-29 18:17:27 +02:00
parent 2a1d18cb9d
commit 494fb2d8c5
355 changed files with 408588 additions and 155997 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Threading.Tasks;
using CitizenFX.Core;
using Mosleys.Shared.Models;
namespace Mosleys.Client {
public static class Utils {
public static async Task<ExhibitVehicle[]> GetAllExhibits() {
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getExhibits");
try {
List<ExhibitVehicle> vehicles = new List<ExhibitVehicle>();
foreach (var exhibit in data.vehicles) {
vehicles.Add(ExhibitVehicle.FromDynamic(exhibit));
}
return vehicles.ToArray();
}
catch (Exception e) {
Debug.WriteLine(e.ToString());
}
return Array.Empty<ExhibitVehicle>();
}
public static async Task<ExhibitVehicle[]> GetPlayerExhibits() {
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getPlayerExhibits");
try {
List<ExhibitVehicle> vehicles = new List<ExhibitVehicle>();
foreach (var exhibit in data.vehicles) {
vehicles.Add(ExhibitVehicle.FromDynamic(exhibit));
}
return vehicles.ToArray();
}
catch (Exception e) {
Debug.WriteLine(e.ToString());
}
return Array.Empty<ExhibitVehicle>();
}
public static async Task<ExhibitVehicle> GetExhibitBySlot(int slot) {
dynamic data = await Mosleys.ServerCallback<dynamic>("mosleys:server:getExhibitBySlot", slot);
return ExhibitVehicle.FromDynamic(data);
}
public static void PrintDynamic(dynamic data, string prefix = "") {
foreach (var element in (data as IDictionary<string, object>)) {
Debug.WriteLine($"{prefix}{element.Key}: {element.Value}");
if (element.Value.GetType() == typeof(ExpandoObject)) {
PrintDynamic(element.Value, prefix + "\t");
}
if (element.Value.GetType() == typeof(List<object>)) {
Debug.WriteLine(prefix + "\t", string.Join(", ", element.Value));
}
}
}
}
}