diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 5f29f71..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -## [Unreleased] - -## [0.1.0] - 2021-07-09 - -- Initial release diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown new file mode 100644 index 0000000..7ad4cac --- /dev/null +++ b/CHANGELOG.mdown @@ -0,0 +1,18 @@ +# ChangeLog + +###### [major.minor.bugfix] - year-month-day + +![Fixed](https://img.shields.io/badge/-Fixed-blue) +![Added](https://img.shields.io/badge/-Added-brightgreen) +![Changed](https://img.shields.io/badge/-Changed-yellow) +![Deprecated](https://img.shields.io/badge/-Deprecated-orange) +![Removed](https://img.shields.io/badge/-Removed-red) + +## [1.0.1](https://github.com/realtradam/FelFlame/releases/tag/1.0.1) - 2021-07-09 +![Fixed](https://img.shields.io/badge/-Fixed-blue) +- Defining attributes in components are no longer allowed to overwrite methods + +## [1.0.0](https://github.com/realtradam/FelFlame/releases/tag/1.0.0) - 2021-07-09 + +![Added](https://img.shields.io/badge/-Added-brightgreen) +- Initial release diff --git a/Gemfile.lock b/Gemfile.lock index 8fcbb4f..f0c22ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - felflame (1.0.0) + felflame (1.0.1) GEM remote: https://rubygems.org/ diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 82abdd9..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2021 realtradam - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb index 1cfd76d..e6c6d91 100644 --- a/lib/felflame/component_manager.rb +++ b/lib/felflame/component_manager.rb @@ -23,7 +23,11 @@ def new(component_name, *attrs, **attrs_with_defaults) const_set(component_name, Class.new(FelFlame::ComponentManager) {}) + attrs.each do |attr| + if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=") + raise NameError.new "The attribute name \"#{attr}\" is already a method" + end FelFlame::Components.const_get(component_name).attr_accessor attr end attrs_with_defaults.each do |attr, _default| diff --git a/lib/felflame/version.rb b/lib/felflame/version.rb index ea5d4b6..6d7db87 100644 --- a/lib/felflame/version.rb +++ b/lib/felflame/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Felflame - VERSION = "1.0.0" + VERSION = "1.0.1" end diff --git a/spec/component_manager_spec.rb b/spec/component_manager_spec.rb index 1c732ac..d99d744 100644 --- a/spec/component_manager_spec.rb +++ b/spec/component_manager_spec.rb @@ -84,6 +84,15 @@ end it 'cant overwrite exiting component managers' do - expect { FelFlame::Components.new('TestComponents') }.to raise_error(NameError) + FelFlame::Components.new('TestComponent1') + expect { FelFlame::Components.new('TestComponent1') }.to raise_error(NameError) + end + + it 'can\'t create an attribute when its name is an existing method' do + expect { FelFlame::Components.new('TestComponent2', :id) }.to raise_error(NameError) + expect { FelFlame::Components.new('TestComponent2', :addition_triggers) }.to raise_error(NameError) + expect { FelFlame::Components.new('TestComponent2', :removal_triggers) }.to raise_error(NameError) + expect { FelFlame::Components.new('TestComponent2', :attr_triggers) }.to raise_error(NameError) + expect { FelFlame::Components.new('TestComponent3', :same, :same) }.to raise_error(NameError) end end diff --git a/spec/system_manager_spec.rb b/spec/system_manager_spec.rb index aab4d8f..f9df439 100644 --- a/spec/system_manager_spec.rb +++ b/spec/system_manager_spec.rb @@ -3,7 +3,7 @@ describe 'Components' do before :all do - @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, name: 'imp', mana: 10) + @component_manager ||= FelFlame::Components.new('TestSystems', health: 10, whatever: 'imp', mana: 10) @@testitr = 999 end @@ -156,17 +156,17 @@ it 'can trigger when a single Component\'s attribute is changed' do @cmp0 = @component_manager.new @cmp1 = @component_manager.new health: 20 - @system.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @cmp0, :whatever expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity0 = FelFlame::Entities.new @entity1 = FelFlame::Entities.new @cmp0 expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'different' + @cmp0.whatever = 'different' expect(@cmp0.health).to eq(15) expect(@cmp1.health).to eq(25) - @cmp1.name = 'different' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(15) expect(@cmp1.health).to eq(25) end @@ -179,15 +179,15 @@ @system.trigger_when_added @component_manager @system.trigger_when_removed @cmp0 @system.trigger_when_removed @component_manager - @system.trigger_when_is_changed @cmp0, :name - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp0, :whatever + @system.trigger_when_is_changed @component_manager, :whatever @system.clear_triggers expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @entity1.add @cmp0, @cmp1 @entity1.remove @cmp0, @cmp1 - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) end @@ -196,15 +196,15 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @cmp0, :name - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @cmp0, :whatever + @system.trigger_when_is_changed @component_manager, :whatever @system.trigger_when_is_changed @cmp0, :mana @system.trigger_when_is_changed @component_manager, :mana - @system.clear_triggers :attr_triggers, :name + @system.clear_triggers :attr_triggers, :whatever expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.mana = 15 @@ -217,17 +217,17 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @cmp0, :name + @system.trigger_when_is_changed @cmp0, :whatever @system.trigger_when_is_changed @cmp0, :mana #expect(@system.attr_triggers).to eq({@cmp0 => [:name, :mana]}) #expect(@cmp0.attr_triggers).to eq({:name => [@system], :mana => [@system]}) - @system.clear_triggers :attr_triggers, :name, component_or_manager: @cmp0 + @system.clear_triggers :attr_triggers, :whatever, component_or_manager: @cmp0 #expect(@system.attr_triggers).to eq({@cmp0 => [:mana]}) #expect(@cmp0.attr_triggers).to eq({:name => [], :mana => [@system]}) expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.mana = 15 @@ -240,13 +240,13 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @component_manager, :whatever @system.trigger_when_is_changed @component_manager, :mana - @system.clear_triggers :attr_triggers, :name, component_or_manager: @component_manager + @system.clear_triggers :attr_triggers, :whatever, component_or_manager: @component_manager expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.mana = 15 @@ -259,13 +259,13 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @component_manager, :whatever @system.trigger_when_is_changed @cmp1, :mana @system.clear_triggers :attr_triggers expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.mana = 15 @@ -278,13 +278,13 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @component_manager, :whatever @system.trigger_when_is_changed @cmp1, :mana @system.clear_triggers :attr_triggers, component_or_manager: @cmp1 expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(20) expect(@cmp1.health).to eq(30) @cmp0.mana = 15 @@ -297,13 +297,13 @@ @cmp0 = @component_manager.new health: 10, mana: 10 @cmp1 = @component_manager.new health: 20, mana: 20 @entity1 = FelFlame::Entities.new - @system.trigger_when_is_changed @component_manager, :name + @system.trigger_when_is_changed @component_manager, :whatever @system.trigger_when_is_changed @cmp1, :mana @system.clear_triggers :attr_triggers, component_or_manager: @component_manager expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) - @cmp0.name = 'something' - @cmp1.name = 'different' + @cmp0.whatever = 'something' + @cmp1.whatever = 'different' expect(@cmp0.health).to eq(10) expect(@cmp1.health).to eq(20) @cmp0.mana = 15