Code Monkey home page Code Monkey logo

dragonruby-game-toolkit-contrib's Introduction

How to Use

This repository requires DragonRuby Game Toolkit. You can purchase a license from http://dragonruby.org.

If your income is below $1000 per month, are a "student", or are a "big time Raspberry PI enthusiast", contact Amir at [email protected] with a short explanation of your current situation, and he'll set you up with a free license, no questions asked.

  1. Download DragonRuby Game Toolkit.
  2. Unzip.
  3. Navigate to your game folder using terminal (the default game folder is ./mygame/app).
  4. git clone https://github.com/DragonRuby/dragonruby-game-toolkit-contrib or download and unzip into the ./mygame/app directory.

IMPORTANT: do not try to symlink the git repo into the ./mygame/app directory (or anything else fancy), the DragonRuby Runtime requires everything to reside in the game directory and will not allow access outside of it.

IMPORTANT: make sure Git is configured to not change line endings (especially if you're cloning on Windows):

git config --system core.autocrlf false
git config --global core.autocrlf false
  1. Your directory structures should look like the following:
DragonRuby
|
+- mygame/
   |
   +- app/
      |
      +- main.rb
      +- repl.rb
      +- documentation/
      |
      +- dragonruby-game-toolkit-contrib/ (this repository)
         |
         +- dragon/
         |  |
         |  +- docs.rb
         |  +- [other source files]
  1. Open main.rb and add a require statement for the source file you want to edit. For example, if you want to edit docs.rb, your mygame/main.rb would look like this:
require 'app/dragonruby-game-toolkit-contrib/dragon/docs.rb'

def tick args
end

Here is the final result

Instructions on how to fork and contribute

Welcome to forking and contributing to this wonderful project. To officially make changes to the OSS you must first fork this repo. To do this you must navigate that lovely cursor up to the top right of this page. You will see three icons: Watch, star and fork. By now you probably know which one you want to click (It is the one titled fork).

Once you have clicked the fork button, a new window will pop up asking you what identity or organization you want to fork to. Choose your main profile. In my case I have already forked to my identity, but you should be able to find your's here.

After cloning your forked version to your local machine, you can make changes to relevant files. When you have wrapped up, you will want to put your name at the top of the file under #Contributors outside of DragonRuby who also hold Copyright:. If this string does not exist go ahead and add it under the top comments. Then you can add to your next commit, commit, and push your changes up to your repo. Now that we have our changes in github we can make a pull request. You are going to want to head on back to your fancy dragonruby-game-toolkit-contrib fork on github. Right below the repo title, you will see a good number of tabs. You are going to click on the one titled Pull requests (It is right next to Code). We are almost contributors! Yay!

Now that we are in the Pull requests tab, you can go ahead and click the nice green button titled New pull request.

You will now be in the pull request compare stage. It goes over all the changes you have made to the base code. This will take you too the comment page. You should always leave a few comments about what you changed and why. It helps people who follow you understand why you made these changes. Now hit that button (It is another green one)!

Congratulations! Once an admin merges your changes, you will be a DragonRubyGTK contributor. Wear that title with pride!

dragonruby-game-toolkit-contrib's People

Contributors

amirrajan avatar awfulcooking avatar cookieoverflow avatar danhealy avatar dependabot[bot] avatar eliraybon avatar girasquid avatar guddler avatar guitsaru avatar hiro-r-b avatar kfischer-okarin avatar leviongit avatar logicalproof avatar marcobrieden avatar mdudzinski avatar mgmarlow avatar mikemar10 avatar niyy avatar oeloeloel avatar p-brighenti avatar parreirat avatar phaedryx avatar pusewicz avatar silverhammermba avatar stardragonex avatar sujayvadlakonda avatar thearjunmdas avatar thedarkmagi avatar thinkerbot avatar zpshank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dragonruby-game-toolkit-contrib's Issues

$gtk.deserialize_state cannot deserialize Arrays

Attempting to deserialize a file that was serialized with $gtk.serialize_state will throw an Exception if the state passed to serialize_state was an Array.

Steps to reproduce

Run:

def tick args
  args.state.replay ||= []

  args.gtk.serialize_state('replay.dat', args.state.replay)

  state = args.gtk.deserialize_state 'replay.dat'
end

Expectation

state would be defined as a new empty Array

Actual

* EXCEPTION:
Failed to eval: []. can't convert Symbol to Integer.
Serialization data may be corrupt.

Notes

The same type of Exception was experienced with an array containing Numbers ([3, 4, 5]) and the hash literal shortcut ([ key: 'value' ])

Bad object instantiation in test swallows the real error

As discussed here:
https://discord.com/channels/608064116111966245/608064116984250379/897617334326403082

If you have a correctly formatted test with the right args,assert method signature, BUT, you are instantiating an object with the wrong parameters, you'll get an error like this:

** Running: test_stuff
I found a test method called :test_stuff. But it needs to have
the following method signature:
#+begin_src
def test_stuff args, assert

end
#+end_src
Please update the method signature to match the code above. If you
did not intend this to be a test method. Rename the method so it does
not start with "test_".

But the test_stuff method has the correct signature.

It seems to get the right message if you're just calling an instance method with the wrong # of params. Constructors is where the test framework gets confused.

hidden_error_dr.zip

POINT.inside_rect? not working correctly when point is a hash

When representing a point with a hash and calling "inside_rect?" the functions seens to not be working correctly.
The case that the error happened was with the point {x: 12, y: 37} and the rect {x: 10, y: 10, w: 4, h: 25} the result should be false.
bug?

Would `samples` folder be included in this project?

I've been checking all the code in samples folder and I've found small details here and there.
I'd like to contribute fixing some of those, but I just wonder if they weren't included here because of the MIT license that have each one of the samples (at least this project have the same one, or I'm missing something else?).

numeric.rb duplicate alias_method :gt and :lt

It looks like there's a copy/paste error in numeric.rb

probably remove the second ones later in the file

diff --git a/dragon/numeric.rb b/dragon/numeric.rb
index 93bacae..3d2a7f6 100644
--- a/dragon/numeric.rb
+++ b/dragon/numeric.rb
@@ -124,11 +124,9 @@ S
     10
   end
 
-  alias_method :gt,        :>
   alias_method :above?,    :>
   alias_method :right_of?, :>
 
-  alias_method :lt,       :<
   alias_method :below?,   :<

Duplicate accessor in console.rb

diff --git a/dragon/console.rb b/dragon/console.rb
index c30c311..f8c46f9 100644
--- a/dragon/console.rb
+++ b/dragon/console.rb
@@ -12,7 +12,7 @@ module GTK
 
     attr_accessor :show_reason, :log, :logo, :background_color,
                   :text_color, :animation_duration,
-                  :max_log_lines, :max_history, :log,
+                  :max_log_lines, :max_history,
                   :last_command_errored, :last_command, :error_color, :shown_at,
                   :header_color, :archived_log, :last_log_lines, :last_log_lines_count,

Docs Corrections

In The docs there is error in DOCS: Array#map and DOCS: Array#each
The line "sprites/square-#{color[:name]}.png"
should be "sprites/square/#{color[:name]}.png"

Feature request: Hotload contrib and other files from the DR install directory

This would help for additions and modifications that developers find useful for their own workflow, as well as make it easier to work on this repo

A proposal would be to include a skeleton directory containing stubs corresponding to files in dragon/:

contrib/
  args.rb
  assert.rb
  console.rb
  (...)

And have the runtime a) hotload those files in development, loaded before game files, b) compile them in similar order on top of the baked-in contrib code.

Symlinking $dr_root/contrib/some_file.rb to a checkout outside of the directory could also work.

Example use case

#91 was extracted from a real-world override placed in app/lib/console.rb:

Expand
module GTK
  class Console
    def eval_the_set_command
      cmd = current_input_str.strip
      if cmd.length != 0
        @log_offset = 0
        prompt.clear

        @command_history.pop while @command_history.length >= @max_history
        @command_history.unshift cmd
        @command_history_index = -1
        @nonhistory_input = ''

        if cmd == 'quit' || cmd == ':wq' || cmd == ':q!' || cmd == ':q' || cmd == ':wqa'
          $gtk.request_quit
        else
          puts "-> #{cmd}"
          begin
            @last_command = cmd

            locals = (@locals ||= {})
            code = "
              #{
                locals.keys.map do |name|
                  "#{name} = locals[:#{name}]"
                end.join "\n"
              }

              _ = (#{cmd})

              local_variables.each do |name|
                locals[name] = eval(name.to_s)
              end

              _
            "

            result = $top_level.instance_eval code

            if result.nil?
              puts "=> nil"
            elsif result == :console_silent_eval
            else
              puts "=> #{result}"
            end
            @last_command_errored = false
          rescue Exception => e
            try_search_docs e
            puts  "* EXCEPTION: #{e}"
          end
        end
      end
    end
  end
end

But I found myself missing the override in other projects.

In order to share it, I'd have to symlink or copy it to each project, and add the require line to my code.

Together those bring enough impedence that I haven't done it for the smallest projects, but those stand to gain equally, if not moreso due to auto-inclusion being more powerful for rapid prototypes.

Related to #52

A reframing or extension of this could be a solution for Amir and Levi's config enhancement, discussed here: #52 (comment)

For example, all rb files under $dr_root/autoload could automatically required.

With a stub named config.rb showing some common overrides.

Thanks

Spelling error in comment

diff --git a/dragon/hotload.rb b/dragon/hotload.rb
index 1cb062a..b8bf439 100644
--- a/dragon/hotload.rb
+++ b/dragon/hotload.rb
@@ -1,7 +1,7 @@
 # coding: utf-8
 # Copyright 2019 DragonRuby LLC
 # MIT License
-# hotlaod.rb has been released under MIT (*only this file*).
+# hotload.rb has been released under MIT (*only this file*).
 
 module GTK
   class Runtime

super args not handled correctly in some cases

$ ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
$ ruby mygame/app/main.rb 
Super Bad:4 5 6
Super Good:4 5 6

# this was on 2.11 
$ ./dragonruby 
** INFO: =app/main.rb= queued to load via ~require~. (-1, -1)
Super Bad:4 2 3
Super Good:4 5 6

using this source

class Parent
  def foo(a=1, b: 2, c:3)
    "#{a} #{b} #{c}"
  end

  def foo2(a=1, b: 2, c:3)
    "#{a} #{b} #{c}"
  end
end

class Child < Parent
  def foo(a=1, b: 2, c:3)
    super
  end

  def foo2(a=1, b: 2, c:3)
    super(a, b:b, c:c)
  end
end

puts "Super Bad:" + Child.new.foo(4, b:5, c:6)
puts "Super Good:" + Child.new.foo2(4, b:5, c:6)

def tick a
end

https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#super

https://medium.com/rubycademy/the-super-keyword-a75b67f46f05#:~:text=When%20a%20method%20with%20arguments,method%20to%20the%20parent%20method.&text=Here%20the%20Child%20class%20inherits%20from%20the%20Parent%20class.

I ran into this when building a subclass off of https://github.com/danhealy/dragonruby-zif/blob/16b5b2daebe30b0aaf5684e285f2bdd3879e349b/app/lib/zif/ui/label.rb#L55 and the initialize method had a ton of arguments that I initially didn't pass to super

Easy work around, but took some time to figure out why the font wasn't getting rendered right.

help.rb line_contract misnamed

Without looking at what this is used for, I'm guessing this change is more correct.
Because there's already a label_contract that looks correct.

diff --git a/dragon/help.rb b/dragon/help.rb
index aee60d8..f2cd577 100644
--- a/dragon/help.rb
+++ b/dragon/help.rb
@@ -45,7 +45,7 @@ S
 S
     end
 
-    def self.label_contract
+    def self.line_contract
       <<-S
 * :line (if :primitive_marker returns :line)
 ** :x, :y, :x2, :y2, :r, :g, :b, :a

entity.rb defines parse_serialization_data, remove the incorrect version

bytemfg — Today at 5:15 PM
Now you got me looking at things, the entity.rb seems to def self.parse_serialization_data twice? Does that even work? (lines 23 and 34)
amirrajan — Today at 5:16 PM
The method on line 23 should be removed
bytemfg — Today at 5:18 PM
k, i'll write up an Issue.

diff --git a/dragon/entity.rb b/dragon/entity.rb
index 09fa794..1d252fa 100644
--- a/dragon/entity.rb
+++ b/dragon/entity.rb
@@ -20,17 +20,6 @@ module GTK
       @strict_entities
     end
 
-    def self.parse_serialization_data data
-      r = Entity.parse_serialization_data data
-      return r if r.is_a? OpenEntity
-      return r if r.is_a? StrictEntity
-      raise <<-S
-* ERROR:
-The save data looks to be corrupt.
-
-S
-    end
-

redefined attr_writer in console_prompt.rb

Now I'm just being pedantic probably because the writer is defined already

      def current_input_str=(str)
diff --git a/dragon/console_prompt.rb b/dragon/console_prompt.rb
index b97bdba..5428254 100644
--- a/dragon/console_prompt.rb
+++ b/dragon/console_prompt.rb
@@ -11,7 +11,8 @@ module GTK
       # ? Can be changed, it was just taken from my editor settings :>
       WORD_LIMITER_CHARS = "`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars
 
-      attr_accessor :current_input_str, :font_style, :console_text_width, :last_input_str, :last_input_str_changed
+      attr_accessor :font_style, :console_text_width, :last_input_str, :last_input_str_changed
+      attr_reader :current_input_str
 
       def initialize(font_style:, text_color:, console_text_width:)
         @prompt = '-> '
@@ -71,14 +72,14 @@ module GTK
         return if @cursor_position.zero?

Zif.roll modifer default should be zero

->  Zif.roll(dice: 1, sides: 1)
=> 3

That was unexpected until I looked up the def and then it made sense.

from zif.rb

  def self.roll(dice: 4, sides: 16, modifier: 2)

Might be better to default the modifier to zero.

Yes, I could also use the roll_raw call instead, but invoking the rule of least surprise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.