ApplySystem.cs 2.8 KB

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