Begin script abstraction
This commit is contained in:
63
ReallifeGamemode.Server.Core.RageMP/RageEntity.cs
Normal file
63
ReallifeGamemode.Server.Core.RageMP/RageEntity.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Server.Common;
|
||||
using ReallifeGamemode.Server.Core.API;
|
||||
|
||||
namespace ReallifeGamemode.Server.Core.RageMP
|
||||
{
|
||||
public class RageEntity : IEntity
|
||||
{
|
||||
|
||||
private readonly GTANetworkAPI.Entity entity;
|
||||
|
||||
public Position Position
|
||||
{
|
||||
get => entity.Position.ToPosition();
|
||||
set => entity.Position = value.ToVector3();
|
||||
}
|
||||
public Position Rotation
|
||||
{
|
||||
get => entity.Rotation.ToPosition();
|
||||
set => entity.Rotation = value.ToVector3();
|
||||
}
|
||||
|
||||
public ulong Handle => entity.Handle.Value;
|
||||
|
||||
public double Heading
|
||||
{
|
||||
get => Rotation.Z;
|
||||
set
|
||||
{
|
||||
var rotation = Rotation;
|
||||
rotation.Z = value;
|
||||
Rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
public RageEntity(GTANetworkAPI.Entity rageEntity)
|
||||
{
|
||||
entity = rageEntity;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
entity.Delete();
|
||||
}
|
||||
|
||||
public void SetSharedData<T>(string key, T data)
|
||||
{
|
||||
entity.SetSharedData(key, data.SerializeJson());
|
||||
}
|
||||
|
||||
public T GetSharedData<T>(string key, T fallback)
|
||||
{
|
||||
if (!entity.HasSharedData(key))
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return (entity.GetSharedData<string>(key)).DeserializeJson<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user