engine_api.vala 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. namespace Crown
  6. {
  7. namespace EngineApi
  8. {
  9. public string compile(Guid id, string data_dir, string platform)
  10. {
  11. return "{\"type\":\"compile\",\"id\":\"%s\",\"data_dir\":\"%s\",\"platform\":\"%s\"}".printf(id.to_string()
  12. , data_dir.replace("\\", "\\\\").replace("\"", "\\\"")
  13. , platform
  14. );
  15. }
  16. public string command(string[] args)
  17. {
  18. StringBuilder sb = new StringBuilder();
  19. for (int i = 0; i < args.length; ++i)
  20. {
  21. string arg = args[i].replace("\\", "\\\\").replace("\"", "\\\"");
  22. sb.append("\"%s\",".printf(arg));
  23. }
  24. return "{\"type\":\"command\",\"args\":[%s]}".printf(sb.str);
  25. }
  26. public string reload(string type, string name)
  27. {
  28. return command({ "reload", type, name });
  29. }
  30. public string pause()
  31. {
  32. return command({ "pause" });
  33. }
  34. public string unpause()
  35. {
  36. return command({ "unpause" });
  37. }
  38. }
  39. }