less copy protection, more size visualization
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

102 lignes
3.2 KiB

  1. function makeObject(name, viewInfo) {
  2. views = {};
  3. console.log(viewInfo)
  4. Object.entries(viewInfo).forEach(([key, value]) => {
  5. console.log(key)
  6. views[key] = {
  7. attributes: {
  8. height: {
  9. name: "Height",
  10. power: 1,
  11. type: "length",
  12. base: value.height
  13. }
  14. },
  15. image: value.image,
  16. name: value.name
  17. }
  18. if (value.mass) {
  19. views[key].attributes[key] = {
  20. name: "Mass",
  21. power: 3,
  22. type: "mass",
  23. base: value.mass
  24. };
  25. }
  26. });
  27. console.log(views)
  28. return makeEntity(name, "Object", views);
  29. }
  30. function makePlanet(name, diameter, mass, image) {
  31. return {
  32. name: name,
  33. constructor: () => makeObject(
  34. name,
  35. {
  36. body: {
  37. height: diameter,
  38. mass: mass,
  39. image: (image === undefined ? {
  40. source: "./media/objects/planet-generic.svg"
  41. } : image),
  42. name: "Body"
  43. }
  44. }
  45. )
  46. };
  47. }
  48. function makeObjects() {
  49. const results = [];
  50. results.push({
  51. name: "Soda Can",
  52. constructor: () => makeObject(
  53. "Soda Can",
  54. {
  55. front: {
  56. height: math.unit(4.83, "inches"),
  57. mass: math.unit(15, "grams"),
  58. image: { source: "./media/objects/soda-can.svg" },
  59. name: "Side"
  60. }
  61. }
  62. )
  63. });
  64. results.push({
  65. name: "Sewing Pin",
  66. constructor: () => makeObject(
  67. "Sewing Pin",
  68. {
  69. side: {
  70. height: math.unit(1.5, "inches"),
  71. image: { source: "./media/objects/sewing-pin.svg" },
  72. name: "Side"
  73. },
  74. top: {
  75. height: math.unit(2, "millimeters"),
  76. image: { source: "./media/objects/pin-head.svg" },
  77. name: "Head"
  78. }
  79. }
  80. )
  81. });
  82. results.push(makePlanet("Mercury", math.unit(4879, "km"), math.unit(0.330e24, "kg")));
  83. results.push(makePlanet("Venus", math.unit(12104, "km"), math.unit(4.87e24, "kg")));
  84. results.push(makePlanet("Earth", math.unit(12756, "km"), math.unit(5.97e24, "kg")));
  85. results.push(makePlanet("Moon", math.unit(3475, "km"), math.unit(0.073e24, "kg")));
  86. results.push(makePlanet("Mars", math.unit(6792, "km"), math.unit(0.642e24, "kg")));
  87. results.push(makePlanet("Jupiter", math.unit(142984, "km"), math.unit(1898e24, "kg")));
  88. results.push(makePlanet("Saturn", math.unit(120536, "km"), math.unit(568e24, "kg"), {source: "./media/objects/saturn.svg"}));
  89. results.push(makePlanet("Uranus", math.unit(51118, "km"), math.unit(86.8e24, "kg")));
  90. results.push(makePlanet("Neptune", math.unit(49528, "km"), math.unit(102e24, "kg")));
  91. results.push(makePlanet("Pluto", math.unit(2370, "km"), math.unit(0.0146e24, "kg")));
  92. return results;
  93. }