voxelamming 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CODE_OF_CONDUCT.md +1 -1
 - data/README.md +20 -14
 - data/index.html +15 -15
 - data/lib/voxelamming/version.rb +1 -1
 - data/lib/voxelamming.rb +132 -32
 - data/voxelamming-0.2.0.gem +0 -0
 - data/voxelamming-0.3.0.gem +0 -0
 - metadata +6 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: cfc40d2cd2af116222490bcd16e2738790ff96fbc9e71c2791786f0e1dad48d5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 963960a9697ba5bf0a6b70c3a6114e06202206d0b80c469c0205df7066438eaf
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5c31b1d345afd868e04a0f8137f4919ceb3483e259ff3d4b4811bf5ab8e064d623763c87ba0a524269ebefc465db5e81f4ac4392088445491fab1a417a7d56fa
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c05d465645818fc0c230607309f0981b079b0f120d54ee515782fced24afac134d741dacfeab22e8cef3ca29e35598e14c94e5ea2b2a88f28125800609ef0432
         
     | 
    
        data/CODE_OF_CONDUCT.md
    CHANGED
    
    | 
         @@ -60,7 +60,7 @@ representative at an online or offline event. 
     | 
|
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
            Instances of abusive, harassing, or otherwise unacceptable behavior may be
         
     | 
| 
       62 
62 
     | 
    
         
             
            reported to the community leaders responsible for enforcement at
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
            creativival@gmail.com.
         
     | 
| 
       64 
64 
     | 
    
         
             
            All complaints will be reviewed and investigated promptly and fairly.
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
            All community leaders are obligated to respect the privacy and security of the
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # Voxelamming
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            This Ruby package converts Python code into JSON format and sends it to the Voxelamming app using WebSockets, allowing users to create 3D voxel models by writing Ruby scripts.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -26,27 +26,27 @@ gem install voxelamming 
     | 
|
| 
       26 
26 
     | 
    
         
             
            require 'voxelamming'
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
            room_name = '1000'
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
            vox = Voxelamming::VoxelammingManager.new(room_name)
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
            vox.set_box_size(0.5)
         
     | 
| 
      
 32 
     | 
    
         
            +
            vox.set_build_interval(0.01)
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
            for i in 0...100
         
     | 
| 
       35 
     | 
    
         
            -
               
     | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
      
 35 
     | 
    
         
            +
              vox.create_box(-1, i, 0, r: 0, g: 1, b: 1)
         
     | 
| 
      
 36 
     | 
    
         
            +
              vox.create_box(0, i, 0, r: 1, g: 0, b: 0)
         
     | 
| 
      
 37 
     | 
    
         
            +
              vox.create_box(1, i, 0, r: 1, g: 1, b: 0)
         
     | 
| 
      
 38 
     | 
    
         
            +
              vox.create_box(2, i, 0, r: 0, g: 1, b: 1)
         
     | 
| 
       39 
39 
     | 
    
         
             
            end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
            for i in 0...50
         
     | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
       43 
     | 
    
         
            -
               
     | 
| 
      
 42 
     | 
    
         
            +
              vox.remove_box(0, i * 2, 0)
         
     | 
| 
      
 43 
     | 
    
         
            +
              vox.remove_box(1, i * 2 + 1, 0)
         
     | 
| 
       44 
44 
     | 
    
         
             
            end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
            vox.send_data
         
     | 
| 
       47 
47 
     | 
    
         
             
            ```
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
            This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the ` 
     | 
| 
      
 49 
     | 
    
         
            +
            This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the `VoxelammingManager` class to build more complex models.
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
            #### Method description
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
         @@ -75,6 +75,12 @@ This code snippet demonstrates a simple example where a red voxel is created at 
     | 
|
| 
       75 
75 
     | 
    
         
             
            | `frame_out()` | Ends recording a frame. | |
         
     | 
| 
       76 
76 
     | 
    
         
             
            | `set_frame_fps(fps)` | Sets the frame rate (default: 2). | `fps`: Frame rate (int) |
         
     | 
| 
       77 
77 
     | 
    
         
             
            | `set_frame_repeats(repeats)` | Sets the number of frame repetitions (default: 10). | `repeats`: Number of repetitions (int) |
         
     | 
| 
      
 78 
     | 
    
         
            +
            | Game Method Name                                                                              | Description | Arguments                                                                                                                                                            |
         
     | 
| 
      
 79 
     | 
    
         
            +
            | `set_game_screen(width, height, angle=90, r=1, g=1, b=0, alpha=0.5)`                | Sets the game screen size. | `width`, `height`: screen size (float), `angle`: angle (float), `r`, `g`, `b`, `alpha`: color (float, 0-1)                                                            |
         
     | 
| 
      
 80 
     | 
    
         
            +
            | `set_game_score(score)`                                                                  | Sets the game score. | `score`: game score (int)                                                                                                                                            |
         
     | 
| 
      
 81 
     | 
    
         
            +
            | `send_game_over()`                                                                       | Triggers game over. |                                                                                                                                                                     |
         
     | 
| 
      
 82 
     | 
    
         
            +
            | `create_sprite(sprite_name, color_list, x, y, direction=90, scale=1, visible=True)`      | Creates a sprite. | `sprite_name`: sprite name (string), `color_list`: dot color data (string), `x`, `y`: position (float), `direction`: angle (float), `scale`: scale (float), `visible`: visibility (boolean) |
         
     | 
| 
      
 83 
     | 
    
         
            +
            | `move_sprite(sprite_name, x, y, direction=90, scale=1, visible=True)`                    | Moves a sprite. | `sprite_name`: sprite name (string), `x`, `y`: position (float), `direction`: angle (float), `scale`: scale (float), `visible`: visibility (boolean)                                  |
         
     | 
| 
       78 
84 
     | 
    
         | 
| 
       79 
85 
     | 
    
         
             
            ## Development
         
     | 
| 
       80 
86 
     | 
    
         | 
| 
         @@ -84,7 +90,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To 
     | 
|
| 
       84 
90 
     | 
    
         | 
| 
       85 
91 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       86 
92 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
            Bug reports and pull requests are welcome on GitHub at https://github.com/creativival/voxelamming_ruby_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ 
     | 
| 
      
 93 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/creativival/voxelamming_ruby_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/voxelamming_ruby_gem/blob/master/CODE_OF_CONDUCT.md).
         
     | 
| 
       88 
94 
     | 
    
         | 
| 
       89 
95 
     | 
    
         
             
            ## License
         
     | 
| 
       90 
96 
     | 
    
         | 
| 
         @@ -92,4 +98,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ 
     | 
|
| 
       92 
98 
     | 
    
         | 
| 
       93 
99 
     | 
    
         
             
            ## Code of Conduct
         
     | 
| 
       94 
100 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
            Everyone interacting in the  
     | 
| 
      
 101 
     | 
    
         
            +
            Everyone interacting in the Voxelamming project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/voxelamming_ruby_gem/blob/master/CODE_OF_CONDUCT.md).
         
     | 
    
        data/index.html
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            <html>
         
     | 
| 
       3 
3 
     | 
    
         
             
            <head>
         
     | 
| 
       4 
4 
     | 
    
         
             
                <meta charset="UTF-8">
         
     | 
| 
       5 
     | 
    
         
            -
                <title> 
     | 
| 
      
 5 
     | 
    
         
            +
                <title>Voxelamming</title>
         
     | 
| 
       6 
6 
     | 
    
         
             
                <style>
         
     | 
| 
       7 
7 
     | 
    
         
             
                    body {
         
     | 
| 
       8 
8 
     | 
    
         
             
                        font-family: sans-serif;
         
     | 
| 
         @@ -58,7 +58,7 @@ 
     | 
|
| 
       58 
58 
     | 
    
         
             
                </style>
         
     | 
| 
       59 
59 
     | 
    
         
             
            </head>
         
     | 
| 
       60 
60 
     | 
    
         
             
            <body>
         
     | 
| 
       61 
     | 
    
         
            -
            <h1><a href="#voxelamminggem" id="voxelamminggem"></a> 
     | 
| 
      
 61 
     | 
    
         
            +
            <h1><a href="#voxelamminggem" id="voxelamminggem"></a>Voxelamming</h1>
         
     | 
| 
       62 
62 
     | 
    
         
             
            <p>This Ruby package converts Python code into JSON format and sends it to the Voxelamming app using WebSockets, allowing users to create 3D voxel models by writing Ruby scripts.</p>
         
     | 
| 
       63 
63 
     | 
    
         
             
            <h2><a href="#whats-voxelamming" id="whats-voxelamming"></a>What's Voxelamming?</h2>
         
     | 
| 
       64 
64 
     | 
    
         
             
            <p align="center"><img src="https://creativival.github.io/voxelamming/image/voxelamming_icon.png" alt="Voxelamming Logo" width="200"/></p>
         
     | 
| 
         @@ -75,26 +75,26 @@ 
     | 
|
| 
       75 
75 
     | 
    
         
             
            <pre><code class="ruby">require 'voxelamming'
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
            room_name = '1000'
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
            vox = Voxelamming::VoxelammingManager.new(room_name)
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
            vox.set_box_size(0.5)
         
     | 
| 
      
 81 
     | 
    
         
            +
            vox.set_build_interval(0.01)
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
       83 
83 
     | 
    
         
             
            for i in 0...100
         
     | 
| 
       84 
     | 
    
         
            -
               
     | 
| 
       85 
     | 
    
         
            -
               
     | 
| 
       86 
     | 
    
         
            -
               
     | 
| 
       87 
     | 
    
         
            -
               
     | 
| 
      
 84 
     | 
    
         
            +
              vox.create_box(-1, i, 0, r: 0, g: 1, b: 1)
         
     | 
| 
      
 85 
     | 
    
         
            +
              vox.create_box(0, i, 0, r: 1, g: 0, b: 0)
         
     | 
| 
      
 86 
     | 
    
         
            +
              vox.create_box(1, i, 0, r: 1, g: 1, b: 0)
         
     | 
| 
      
 87 
     | 
    
         
            +
              vox.create_box(2, i, 0, r: 0, g: 1, b: 1)
         
     | 
| 
       88 
88 
     | 
    
         
             
            end
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
90 
     | 
    
         
             
            for i in 0...50
         
     | 
| 
       91 
     | 
    
         
            -
               
     | 
| 
       92 
     | 
    
         
            -
               
     | 
| 
      
 91 
     | 
    
         
            +
              vox.remove_box(0, i * 2, 0)
         
     | 
| 
      
 92 
     | 
    
         
            +
              vox.remove_box(1, i * 2 + 1, 0)
         
     | 
| 
       93 
93 
     | 
    
         
             
            end
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
      
 95 
     | 
    
         
            +
            vox.send_data
         
     | 
| 
       96 
96 
     | 
    
         
             
            </code></pre>
         
     | 
| 
       97 
     | 
    
         
            -
            <p>This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the <code> 
     | 
| 
      
 97 
     | 
    
         
            +
            <p>This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the <code>VoxelammingManager</code> class to build more complex models.</p>
         
     | 
| 
       98 
98 
     | 
    
         
             
            <h4><a href="#method-description" id="method-description"></a>Method description</h4>
         
     | 
| 
       99 
99 
     | 
    
         
             
            <table>
         
     | 
| 
       100 
100 
     | 
    
         
             
                <thead>
         
     | 
| 
         @@ -130,10 +130,10 @@ build_box.send_data 
     | 
|
| 
       130 
130 
     | 
    
         
             
            <p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake test</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
         
     | 
| 
       131 
131 
     | 
    
         
             
            <p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
         
     | 
| 
       132 
132 
     | 
    
         
             
            <h2><a href="#contributing" id="contributing"></a>Contributing</h2>
         
     | 
| 
       133 
     | 
    
         
            -
            <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/[USERNAME]/ 
     | 
| 
      
 133 
     | 
    
         
            +
            <p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/[USERNAME]/voxelamming_ruby_gem">https://github.com/[USERNAME]/voxelamming_ruby_gem</a>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="https://github.com/[USERNAME]/voxelamming_ruby_gem/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
         
     | 
| 
       134 
134 
     | 
    
         
             
            <h2><a href="#license" id="license"></a>License</h2>
         
     | 
| 
       135 
135 
     | 
    
         
             
            <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
         
     | 
| 
       136 
136 
     | 
    
         
             
            <h2><a href="#code-of-conduct" id="code-of-conduct"></a>Code of Conduct</h2>
         
     | 
| 
       137 
     | 
    
         
            -
            <p>Everyone interacting in the  
     | 
| 
      
 137 
     | 
    
         
            +
            <p>Everyone interacting in the Voxelamming project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/[USERNAME]/voxelamming_ruby_gem/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
         
     | 
| 
       138 
138 
     | 
    
         
             
            </body>
         
     | 
| 
       139 
139 
     | 
    
         
             
            </html>
         
     | 
    
        data/lib/voxelamming/version.rb
    CHANGED
    
    
    
        data/lib/voxelamming.rb
    CHANGED
    
    | 
         @@ -17,7 +17,7 @@ module Voxelamming 
     | 
|
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              # Main process
         
     | 
| 
       20 
     | 
    
         
            -
              class  
     | 
| 
      
 20 
     | 
    
         
            +
              class VoxelammingManager
         
     | 
| 
       21 
21 
     | 
    
         
             
                @@texture_names = ["grass", "stone", "dirt", "planks", "bricks"]
         
     | 
| 
       22 
22 
     | 
    
         
             
                @@model_names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto", "Sun",
         
     | 
| 
       23 
23 
     | 
    
         
             
                                 "Moon", "ToyBiplane", "ToyCar", "Drummer", "Robot", "ToyRocket", "RocketToy1", "RocketToy2", "Skull"]
         
     | 
| 
         @@ -33,11 +33,15 @@ module Voxelamming 
     | 
|
| 
       33 
33 
     | 
    
         
             
                  @animation = [0, 0, 0, 0, 0, 0, 1, 0]
         
     | 
| 
       34 
34 
     | 
    
         
             
                  @boxes = []
         
     | 
| 
       35 
35 
     | 
    
         
             
                  @frames = []
         
     | 
| 
       36 
     | 
    
         
            -
                  @ 
     | 
| 
      
 36 
     | 
    
         
            +
                  @sentences = []
         
     | 
| 
       37 
37 
     | 
    
         
             
                  @lights = []
         
     | 
| 
       38 
38 
     | 
    
         
             
                  @commands = []
         
     | 
| 
       39 
39 
     | 
    
         
             
                  @models = []
         
     | 
| 
       40 
40 
     | 
    
         
             
                  @model_moves = []
         
     | 
| 
      
 41 
     | 
    
         
            +
                  @sprites = []
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @sprite_moves = []
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @game_score = -1
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @game_screen = []  # width, height, angle=90, red=1, green=1, blue=1, alpha=0.5
         
     | 
| 
       41 
45 
     | 
    
         
             
                  @size = 1
         
     | 
| 
       42 
46 
     | 
    
         
             
                  @shape = 'box'
         
     | 
| 
       43 
47 
     | 
    
         
             
                  @is_metallic = 0
         
     | 
| 
         @@ -46,6 +50,9 @@ module Voxelamming 
     | 
|
| 
       46 
50 
     | 
    
         
             
                  @build_interval = 0.01
         
     | 
| 
       47 
51 
     | 
    
         
             
                  @is_framing = false
         
     | 
| 
       48 
52 
     | 
    
         
             
                  @frame_id = 0
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @websocket = nil
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @last_sent_time = nil
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @timer = nil
         
     | 
| 
       49 
56 
     | 
    
         
             
                end
         
     | 
| 
       50 
57 
     | 
    
         | 
| 
       51 
58 
     | 
    
         
             
                def clear_data
         
     | 
| 
         @@ -58,7 +65,11 @@ module Voxelamming 
     | 
|
| 
       58 
65 
     | 
    
         
             
                  @animation = [0, 0, 0, 0, 0, 0, 1, 0]
         
     | 
| 
       59 
66 
     | 
    
         
             
                  @boxes = []
         
     | 
| 
       60 
67 
     | 
    
         
             
                  @frames = []
         
     | 
| 
       61 
     | 
    
         
            -
                  @ 
     | 
| 
      
 68 
     | 
    
         
            +
                  @sentences = []
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @sprites = []
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @sprite_moves = []
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @game_score = -1
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @game_screen = []  # width, height, angle=90, red=1, green=1, blue=1, alpha=0.5
         
     | 
| 
       62 
73 
     | 
    
         
             
                  @lights = []
         
     | 
| 
       63 
74 
     | 
    
         
             
                  @commands = []
         
     | 
| 
       64 
75 
     | 
    
         
             
                  @models = []
         
     | 
| 
         @@ -119,8 +130,8 @@ module Voxelamming 
     | 
|
| 
       119 
130 
     | 
    
         
             
                    x, y, z = round_numbers([x, y, z])
         
     | 
| 
       120 
131 
     | 
    
         | 
| 
       121 
132 
     | 
    
         
             
                    # Compute the rotation after transform
         
     | 
| 
       122 
     | 
    
         
            -
                     
     | 
| 
       123 
     | 
    
         
            -
                    rotate_matrix = matrix_multiply( 
     | 
| 
      
 133 
     | 
    
         
            +
                    transform_rotation_matrix = get_rotation_matrix(-pitch, -yaw, -roll)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    rotate_matrix = matrix_multiply(transform_rotation_matrix, base_rotation_matrix)
         
     | 
| 
       124 
135 
     | 
    
         
             
                    @matrix_transform = [x, y, z, *rotate_matrix[0], *rotate_matrix[1], *rotate_matrix[2]]
         
     | 
| 
       125 
136 
     | 
    
         
             
                  else
         
     | 
| 
       126 
137 
     | 
    
         
             
                    x, y, z = round_numbers([x, y, z])
         
     | 
| 
         @@ -196,11 +207,11 @@ module Voxelamming 
     | 
|
| 
       196 
207 
     | 
    
         
             
                  @build_interval = interval
         
     | 
| 
       197 
208 
     | 
    
         
             
                end
         
     | 
| 
       198 
209 
     | 
    
         | 
| 
       199 
     | 
    
         
            -
                def write_sentence(sentence, x, y, z, r: 1, g: 1, b: 1, alpha: 1)
         
     | 
| 
      
 210 
     | 
    
         
            +
                def write_sentence(sentence, x, y, z, r: 1, g: 1, b: 1, alpha: 1, font_size: 8, is_fixed_width: false)
         
     | 
| 
       200 
211 
     | 
    
         
             
                  x, y, z = round_numbers([x, y, z]).map(&:to_s)
         
     | 
| 
       201 
212 
     | 
    
         
             
                  r, g, b, alpha = round_two_decimals([r, g, b, alpha])
         
     | 
| 
       202 
     | 
    
         
            -
                  r, g, b, alpha =  [r, g, b, alpha].map(&:floor).map(&:to_s)
         
     | 
| 
       203 
     | 
    
         
            -
                  @ 
     | 
| 
      
 213 
     | 
    
         
            +
                  r, g, b, alpha, font_size =  [r, g, b, alpha, font_size].map(&:floor).map(&:to_s)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  @sentences << [sentence, x, y, z, r, g, b, alpha, font_size, is_fixed_width ? "1" : "0"]
         
     | 
| 
       204 
215 
     | 
    
         
             
                end
         
     | 
| 
       205 
216 
     | 
    
         | 
| 
       206 
217 
     | 
    
         
             
                def set_light(x, y, z, r: 1, g: 1, b: 1, alpha: 1, intensity: 1000, interval: 1, light_type: 'point')
         
     | 
| 
         @@ -308,6 +319,65 @@ module Voxelamming 
     | 
|
| 
       308 
319 
     | 
    
         
             
                  @model_moves << [entity_name, x, y, z, pitch, yaw, roll, scale]
         
     | 
| 
       309 
320 
     | 
    
         
             
                end
         
     | 
| 
       310 
321 
     | 
    
         | 
| 
      
 322 
     | 
    
         
            +
                # Game API
         
     | 
| 
      
 323 
     | 
    
         
            +
             
     | 
| 
      
 324 
     | 
    
         
            +
                def set_game_screen(width, height, angle = 90, r = 1, g = 1, b = 0, alpha = 0.5)
         
     | 
| 
      
 325 
     | 
    
         
            +
                  @game_screen = [width, height, angle, r, g, b, alpha]
         
     | 
| 
      
 326 
     | 
    
         
            +
                end
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                def set_game_score(score)
         
     | 
| 
      
 329 
     | 
    
         
            +
                  @game_score = score.to_f
         
     | 
| 
      
 330 
     | 
    
         
            +
                end
         
     | 
| 
      
 331 
     | 
    
         
            +
             
     | 
| 
      
 332 
     | 
    
         
            +
                def send_game_over
         
     | 
| 
      
 333 
     | 
    
         
            +
                  @commands << 'gameOver'
         
     | 
| 
      
 334 
     | 
    
         
            +
                end
         
     | 
| 
      
 335 
     | 
    
         
            +
             
     | 
| 
      
 336 
     | 
    
         
            +
                def set_rotation_style(sprite_name, rotation_style = 'all around')
         
     | 
| 
      
 337 
     | 
    
         
            +
                  @rotation_styles[sprite_name] = rotation_style
         
     | 
| 
      
 338 
     | 
    
         
            +
                end
         
     | 
| 
      
 339 
     | 
    
         
            +
             
     | 
| 
      
 340 
     | 
    
         
            +
                def create_sprite(sprite_name, color_list, x, y, direction = 0, scale = 1, visible = true)
         
     | 
| 
      
 341 
     | 
    
         
            +
                  # 新しいスプライトデータを配列に追加
         
     | 
| 
      
 342 
     | 
    
         
            +
                  x, y, direction = round_numbers([x, y, direction])
         
     | 
| 
      
 343 
     | 
    
         
            +
                  x, y, direction, scale = [x, y, direction, scale].map(&:to_s)
         
     | 
| 
      
 344 
     | 
    
         
            +
                  @sprites << [sprite_name, color_list, x, y, direction, scale, visible ? '1' : '0']
         
     | 
| 
      
 345 
     | 
    
         
            +
                end
         
     | 
| 
      
 346 
     | 
    
         
            +
             
     | 
| 
      
 347 
     | 
    
         
            +
                def move_sprite(sprite_name, x, y, direction = 0, scale = 1, visible = true)
         
     | 
| 
      
 348 
     | 
    
         
            +
                  # x, y, directionを丸める
         
     | 
| 
      
 349 
     | 
    
         
            +
                  x, y, direction = round_numbers([x, y, direction])
         
     | 
| 
      
 350 
     | 
    
         
            +
                  x, y, direction, scale = [x, y, direction, scale].map(&:to_s)
         
     | 
| 
      
 351 
     | 
    
         
            +
             
     | 
| 
      
 352 
     | 
    
         
            +
                  # rotation_styleを取得
         
     | 
| 
      
 353 
     | 
    
         
            +
                  if @rotation_styles.has_key?(sprite_name)
         
     | 
| 
      
 354 
     | 
    
         
            +
                    rotation_style = @rotation_styles[sprite_name]
         
     | 
| 
      
 355 
     | 
    
         
            +
             
     | 
| 
      
 356 
     | 
    
         
            +
                    # rotation_styleが変更された場合、新しいスプライトデータを配列に追加
         
     | 
| 
      
 357 
     | 
    
         
            +
                    case rotation_style
         
     | 
| 
      
 358 
     | 
    
         
            +
                    when 'left-right'
         
     | 
| 
      
 359 
     | 
    
         
            +
                      direction_mod = direction.to_i % 360 # 常に0から359の範囲で処理(常に正の数になる)
         
     | 
| 
      
 360 
     | 
    
         
            +
                      if direction_mod > 90 && direction_mod < 270
         
     | 
| 
      
 361 
     | 
    
         
            +
                        direction = '-180' # -180は左右反転するようにボクセラミング側で実装されている
         
     | 
| 
      
 362 
     | 
    
         
            +
                      else
         
     | 
| 
      
 363 
     | 
    
         
            +
                        direction = '0'
         
     | 
| 
      
 364 
     | 
    
         
            +
                      end
         
     | 
| 
      
 365 
     | 
    
         
            +
                    when "don't rotate"
         
     | 
| 
      
 366 
     | 
    
         
            +
                      direction = '0'
         
     | 
| 
      
 367 
     | 
    
         
            +
                    else
         
     | 
| 
      
 368 
     | 
    
         
            +
                      direction = direction.to_s
         
     | 
| 
      
 369 
     | 
    
         
            +
                    end
         
     | 
| 
      
 370 
     | 
    
         
            +
                  else
         
     | 
| 
      
 371 
     | 
    
         
            +
                    # rotation_styleが設定されていない場合、そのままの値を使う
         
     | 
| 
      
 372 
     | 
    
         
            +
                    direction = direction.to_s
         
     | 
| 
      
 373 
     | 
    
         
            +
                  end
         
     | 
| 
      
 374 
     | 
    
         
            +
             
     | 
| 
      
 375 
     | 
    
         
            +
                  # sprites配列から同じスプライト名の要素を削除
         
     | 
| 
      
 376 
     | 
    
         
            +
                  @sprite_moves.reject! { |sprite_info| sprite_info[0] == sprite_name }
         
     | 
| 
      
 377 
     | 
    
         
            +
             
     | 
| 
      
 378 
     | 
    
         
            +
                  # 新しいスプライトデータを配列に追加
         
     | 
| 
      
 379 
     | 
    
         
            +
                  @sprite_moves << [sprite_name, x, y, direction, scale, visible ? '1' : '0']
         
     | 
| 
      
 380 
     | 
    
         
            +
                end
         
     | 
| 
       311 
381 
     | 
    
         | 
| 
       312 
382 
     | 
    
         
             
                def send_data(name: '')
         
     | 
| 
       313 
383 
     | 
    
         
             
                  puts 'send_data'
         
     | 
| 
         @@ -319,11 +389,15 @@ module Voxelamming 
     | 
|
| 
       319 
389 
     | 
    
         
             
                    "animation": @animation,
         
     | 
| 
       320 
390 
     | 
    
         
             
                    "boxes": @boxes,
         
     | 
| 
       321 
391 
     | 
    
         
             
                    "frames": @frames,
         
     | 
| 
       322 
     | 
    
         
            -
                    " 
     | 
| 
      
 392 
     | 
    
         
            +
                    "sentences": @sentences,
         
     | 
| 
       323 
393 
     | 
    
         
             
                    "lights": @lights,
         
     | 
| 
       324 
394 
     | 
    
         
             
                    "commands": @commands,
         
     | 
| 
       325 
395 
     | 
    
         
             
                    "models": @models,
         
     | 
| 
       326 
396 
     | 
    
         
             
                    "modelMoves": @model_moves,
         
     | 
| 
      
 397 
     | 
    
         
            +
                    "sprites": @sprites,
         
     | 
| 
      
 398 
     | 
    
         
            +
                    "spriteMoves": @sprite_moves,
         
     | 
| 
      
 399 
     | 
    
         
            +
                    "gameScore": @game_score,
         
     | 
| 
      
 400 
     | 
    
         
            +
                    "gameScreen": @game_screen,
         
     | 
| 
       327 
401 
     | 
    
         
             
                    "size": @size,
         
     | 
| 
       328 
402 
     | 
    
         
             
                    "shape": @shape,
         
     | 
| 
       329 
403 
     | 
    
         
             
                    "interval": @build_interval,
         
     | 
| 
         @@ -335,35 +409,61 @@ module Voxelamming 
     | 
|
| 
       335 
409 
     | 
    
         
             
                  }.to_json
         
     | 
| 
       336 
410 
     | 
    
         | 
| 
       337 
411 
     | 
    
         
             
                  EM.run do
         
     | 
| 
       338 
     | 
    
         
            -
                     
     | 
| 
       339 
     | 
    
         
            -
             
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
       341 
     | 
    
         
            -
                       
     | 
| 
       342 
     | 
    
         
            -
             
     | 
| 
       343 
     | 
    
         
            -
             
     | 
| 
       344 
     | 
    
         
            -
             
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
             
     | 
| 
       347 
     | 
    
         
            -
                       
     | 
| 
       348 
     | 
    
         
            -
             
     | 
| 
       349 
     | 
    
         
            -
                       
     | 
| 
       350 
     | 
    
         
            -
                         
     | 
| 
      
 412 
     | 
    
         
            +
                    if @websocket.nil?
         
     | 
| 
      
 413 
     | 
    
         
            +
                      @websocket = Faye::WebSocket::Client.new('wss://websocket.voxelamming.com')
         
     | 
| 
      
 414 
     | 
    
         
            +
             
     | 
| 
      
 415 
     | 
    
         
            +
                      @websocket.on :open do |_event|
         
     | 
| 
      
 416 
     | 
    
         
            +
                        p [:open]
         
     | 
| 
      
 417 
     | 
    
         
            +
                        puts 'WebSocket connection open'
         
     | 
| 
      
 418 
     | 
    
         
            +
                        @websocket.send(@room_name)
         
     | 
| 
      
 419 
     | 
    
         
            +
                        puts "Joined room: #{@room_name}"
         
     | 
| 
      
 420 
     | 
    
         
            +
                        send_data_to_server(data_to_send)
         
     | 
| 
      
 421 
     | 
    
         
            +
                      end
         
     | 
| 
      
 422 
     | 
    
         
            +
             
     | 
| 
      
 423 
     | 
    
         
            +
                      @websocket.on :error do |event|
         
     | 
| 
      
 424 
     | 
    
         
            +
                        puts "WebSocket error: #{event.message}"
         
     | 
| 
       351 
425 
     | 
    
         
             
                        EM.stop
         
     | 
| 
       352 
426 
     | 
    
         
             
                      end
         
     | 
| 
       353 
     | 
    
         
            -
                    end
         
     | 
| 
       354 
427 
     | 
    
         | 
| 
       355 
     | 
    
         
            -
             
     | 
| 
       356 
     | 
    
         
            -
             
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
      
 428 
     | 
    
         
            +
                      @websocket.on :close do |_event|
         
     | 
| 
      
 429 
     | 
    
         
            +
                        puts 'WebSocket connection closed'
         
     | 
| 
      
 430 
     | 
    
         
            +
                        EM.stop
         
     | 
| 
      
 431 
     | 
    
         
            +
                      end
         
     | 
| 
      
 432 
     | 
    
         
            +
                    else
         
     | 
| 
      
 433 
     | 
    
         
            +
                      send_data_to_server(data_to_send)
         
     | 
| 
       358 
434 
     | 
    
         
             
                    end
         
     | 
| 
      
 435 
     | 
    
         
            +
                  end
         
     | 
| 
      
 436 
     | 
    
         
            +
                end
         
     | 
| 
      
 437 
     | 
    
         
            +
             
     | 
| 
      
 438 
     | 
    
         
            +
                def send_data_to_server(data)
         
     | 
| 
      
 439 
     | 
    
         
            +
                  if @websocket && @websocket.ready_state == Faye::WebSocket::API::OPEN
         
     | 
| 
      
 440 
     | 
    
         
            +
                    @websocket.send(data)
         
     | 
| 
      
 441 
     | 
    
         
            +
                    puts 'Sent data to server'
         
     | 
| 
      
 442 
     | 
    
         
            +
                    @last_sent_time = Time.now
         
     | 
| 
      
 443 
     | 
    
         
            +
             
     | 
| 
      
 444 
     | 
    
         
            +
                    reset_close_timer
         
     | 
| 
      
 445 
     | 
    
         
            +
                  end
         
     | 
| 
      
 446 
     | 
    
         
            +
                end
         
     | 
| 
       359 
447 
     | 
    
         | 
| 
       360 
     | 
    
         
            -
             
     | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
      
 448 
     | 
    
         
            +
                def reset_close_timer
         
     | 
| 
      
 449 
     | 
    
         
            +
                  EM.cancel_timer(@timer) if @timer
         
     | 
| 
      
 450 
     | 
    
         
            +
             
     | 
| 
      
 451 
     | 
    
         
            +
                  @timer = EM.add_timer(2) do
         
     | 
| 
      
 452 
     | 
    
         
            +
                    if Time.now - @last_sent_time >= 2
         
     | 
| 
      
 453 
     | 
    
         
            +
                      close_connection
         
     | 
| 
       363 
454 
     | 
    
         
             
                    end
         
     | 
| 
       364 
455 
     | 
    
         
             
                  end
         
     | 
| 
       365 
456 
     | 
    
         
             
                end
         
     | 
| 
       366 
457 
     | 
    
         | 
| 
      
 458 
     | 
    
         
            +
                def close_connection
         
     | 
| 
      
 459 
     | 
    
         
            +
                  if @websocket
         
     | 
| 
      
 460 
     | 
    
         
            +
                    puts 'Closing WebSocket connection.'
         
     | 
| 
      
 461 
     | 
    
         
            +
                    @websocket.close
         
     | 
| 
      
 462 
     | 
    
         
            +
                    @websocket = nil
         
     | 
| 
      
 463 
     | 
    
         
            +
                    EM.stop
         
     | 
| 
      
 464 
     | 
    
         
            +
                  end
         
     | 
| 
      
 465 
     | 
    
         
            +
                end
         
     | 
| 
      
 466 
     | 
    
         
            +
             
     | 
| 
       367 
467 
     | 
    
         
             
                def round_numbers(num_list)
         
     | 
| 
       368 
468 
     | 
    
         
             
                  if @is_allowed_float == 1
         
     | 
| 
       369 
469 
     | 
    
         
             
                    round_two_decimals(num_list)
         
     | 
| 
         @@ -381,8 +481,8 @@ module Voxelamming 
     | 
|
| 
       381 
481 
     | 
    
         
             
              class Turtle
         
     | 
| 
       382 
482 
     | 
    
         
             
                include Math
         
     | 
| 
       383 
483 
     | 
    
         | 
| 
       384 
     | 
    
         
            -
                def initialize( 
     | 
| 
       385 
     | 
    
         
            -
                  @ 
     | 
| 
      
 484 
     | 
    
         
            +
                def initialize(voxelamming_instance)
         
     | 
| 
      
 485 
     | 
    
         
            +
                  @vox = voxelamming_instance
         
     | 
| 
       386 
486 
     | 
    
         
             
                  @x = 0
         
     | 
| 
       387 
487 
     | 
    
         
             
                  @y = 0
         
     | 
| 
       388 
488 
     | 
    
         
             
                  @z = 0
         
     | 
| 
         @@ -400,7 +500,7 @@ module Voxelamming 
     | 
|
| 
       400 
500 
     | 
    
         
             
                  x, y, z = x.round(3), y.round(3), z.round(3)
         
     | 
| 
       401 
501 
     | 
    
         | 
| 
       402 
502 
     | 
    
         
             
                  if @drawable
         
     | 
| 
       403 
     | 
    
         
            -
                    @ 
     | 
| 
      
 503 
     | 
    
         
            +
                    @vox.draw_line(@x, @y, @z, x, y, z, r: @color[0], g: @color[1], b: @color[2])
         
     | 
| 
       404 
504 
     | 
    
         
             
                  end
         
     | 
| 
       405 
505 
     | 
    
         | 
| 
       406 
506 
     | 
    
         
             
                  @x = x
         
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: voxelamming
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - creativival
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-08- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-08-27 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: faye-websocket
         
     | 
| 
         @@ -42,14 +42,16 @@ files: 
     | 
|
| 
       42 
42 
     | 
    
         
             
            - lib/voxelamming.rb
         
     | 
| 
       43 
43 
     | 
    
         
             
            - lib/voxelamming/version.rb
         
     | 
| 
       44 
44 
     | 
    
         
             
            - sig/voxelamming.rbs
         
     | 
| 
      
 45 
     | 
    
         
            +
            - voxelamming-0.2.0.gem
         
     | 
| 
      
 46 
     | 
    
         
            +
            - voxelamming-0.3.0.gem
         
     | 
| 
       45 
47 
     | 
    
         
             
            homepage: https://creativival.github.io/voxelamming
         
     | 
| 
       46 
48 
     | 
    
         
             
            licenses:
         
     | 
| 
       47 
49 
     | 
    
         
             
            - MIT
         
     | 
| 
       48 
50 
     | 
    
         
             
            metadata:
         
     | 
| 
       49 
51 
     | 
    
         
             
              allowed_push_host: https://rubygems.org
         
     | 
| 
       50 
52 
     | 
    
         
             
              homepage_uri: https://creativival.github.io/voxelamming
         
     | 
| 
       51 
     | 
    
         
            -
              source_code_uri: https://github.com/creativival/ 
     | 
| 
       52 
     | 
    
         
            -
              changelog_uri: https://creativival.github.io/ 
     | 
| 
      
 53 
     | 
    
         
            +
              source_code_uri: https://github.com/creativival/voxelamming_ruby_gem
         
     | 
| 
      
 54 
     | 
    
         
            +
              changelog_uri: https://creativival.github.io/voxelamming_ruby_gem/CHANGELOG.md
         
     | 
| 
       53 
55 
     | 
    
         
             
            post_install_message:
         
     | 
| 
       54 
56 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       55 
57 
     | 
    
         
             
            require_paths:
         
     |