ApplySystem.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma warning disable CS1591
  2. #pragma warning disable CS0618
  3. using Solana.Unity.Wallet;
  4. using System;
  5. using System.Linq;
  6. using World.Program;
  7. namespace Bolt {
  8. public partial class World {
  9. public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
  10. PublicKey world,
  11. PublicKey system,
  12. EntityType[] systemInput,
  13. byte[] args,
  14. PublicKey authority,
  15. PublicKey sessionToken = null,
  16. PublicKey programId = null)
  17. {
  18. var entityTypes = systemInput.Select(e => new WorldProgram.EntityType(e.Entity, e.Components, e.Seeds)).ToArray();
  19. return WorldProgram.ApplySystem(world, system, entityTypes, args, authority, sessionToken, programId);
  20. }
  21. public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
  22. PublicKey world,
  23. PublicKey system,
  24. EntityType[] systemInput,
  25. object args,
  26. PublicKey authority,
  27. PublicKey sessionToken = null,
  28. PublicKey programId = null)
  29. {
  30. var entityTypes = systemInput.Select(e => new WorldProgram.EntityType(e.Entity, e.Components, e.Seeds)).ToArray();
  31. return WorldProgram.ApplySystem(world, system, entityTypes, SerializeArgs(args), authority, sessionToken, programId);
  32. }
  33. public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
  34. PublicKey world,
  35. PublicKey system,
  36. EntityType[] systemInput,
  37. PublicKey authority,
  38. PublicKey sessionToken = null,
  39. PublicKey programId = null)
  40. {
  41. var entityTypes = systemInput.Select(e => new WorldProgram.EntityType(e.Entity, e.Components, e.Seeds)).ToArray();
  42. return WorldProgram.ApplySystem(world, system, entityTypes, new byte[] {}, authority, sessionToken, programId);
  43. }
  44. public class EntityType {
  45. public PublicKey[] Components { get; set; }
  46. public string[] Seeds { get; set; }
  47. public PublicKey Entity { get; set; }
  48. public EntityType(PublicKey entity, PublicKey[] componentsIds)
  49. {
  50. Components = componentsIds;
  51. Seeds = new string[Components.Length];
  52. Entity = entity;
  53. Array.Fill(Seeds, "");
  54. }
  55. public EntityType(PublicKey entity, PublicKey[] componentsIds, string[] seeds)
  56. {
  57. Components = componentsIds;
  58. Seeds = seeds;
  59. Entity = entity;
  60. if (Seeds.Length != Components.Length)
  61. {
  62. throw new ArgumentException("Seeds must be the same length as components");
  63. }
  64. }
  65. }
  66. }
  67. }