Skip to content

Commit

Permalink
✨ feat: add view for current date (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszNaKodach authored Sep 27, 2024
1 parent 1438001 commit 61e4539
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 39 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Shows how to use Domain-Driven Design, Event Storming, Event Modeling and Event

This project probably won't be fully-functional HOMM3 engine implementation, because it's done for education purposes.

## How to run the project?

1. `cd heroesofddd_rails_application`
2. `docker compose up`
3. `bundle install`
4. `rails db:create`
5. `rails db:migrate`
6. `rails db:seed`
7. `rails server`

Go to the url and play around with the app: http://localhost:3000/heroes/games/fcc8f601-76cb-4b5a-972d-b7431303f69a/creature_recruitment/dwellings/cecc4307-e940-4ef2-8436-80c475729938

## Modules

Modules (mostly designed using Bounded Context heuristic) are designed and documented on EventModeling below.
Expand Down
10 changes: 9 additions & 1 deletion heroesofddd_rails_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ Generate code in one file for LLM context:
- first day -> increase dwelling population / renew - increase for simplicity
- calendar read model

add UI to passing days in calendar, show astrologers on first week day
add UI to passing days in calendar, show astrologers on first week day


```
rake db:drop:all
rake db:create:all
rake db:migrate
rake db:seed
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
*= require_tree .
*= require_self
*/
@import 'creature_recruitment';
@import 'creature_recruitment';
@import 'current_date';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.current-date {
margin: 2rem;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
font-weight: bold;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
require "heroes/creature_recruitment/read/dwelling_read_model"
require "heroes/calendar/read/current_date_read_model"
require "heroes/creature_recruitment/write/recruit_creature/command_recruit_creature"
require "building_blocks/application/app_context"

module Heroes
module CreatureRecruitment
class DwellingsController < ApplicationController
Expand All @@ -6,6 +11,7 @@ def show
dwelling_id = params[:id]
@dwelling = DwellingReadModel::State.find_by(game_id: game_id, id: dwelling_id)
if @dwelling
@current_date = Heroes::Calendar::CurrentDateReadModel::State.find_by(game_id: game_id)
render template: "heroes/creature_recruitment/dwellings/index"
else
render json: { error: "Dwelling not found" }, status: :not_found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="current-date">
<% if @current_date %>
<p>Month: <%= @current_date.month %>, Week: <%= @current_date.week %>, Day: <%= @current_date.day %></p>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
<button type="button" class="recruitment__button recruitment__button--recruit" id="recruit-btn">
<%= image_tag "button_recruit.png", alt: "Recruit", class: "recruitment__button-image" %>
</button>
<!-- <button type="button" class="recruitment__button recruitment__button--cancel" id="cancel-btn">-->
<%#= image_tag "button_cancel.png", alt: "Cancel", class: "recruitment__button-image" %>
<!-- </button>-->
<button type="button" class="recruitment__button recruitment__button--cancel" id="cancel-btn" disabled>
<%= image_tag "button_cancel.png", alt: "Cancel", class: "recruitment__button-image" %>
</button>
</div>
</div>
<div class="recruitment__message-box">
Expand All @@ -67,6 +67,7 @@
</p>
</div>
</div>
<%= render 'heroes/calendar/current_date' %>
</div>
<%= form.hidden_field :recruit_count, id: 'recruit-count-input' %>
<% end %>
Expand Down

This file was deleted.

38 changes: 38 additions & 0 deletions heroesofddd_rails_application/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,41 @@
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end

require "building_blocks/application/app_context"

game_id = "fcc8f601-76cb-4b5a-972d-b7431303f69a"
puts "🎮 Loading initial data for game #{game_id}"
metadata = ::BuildingBlocks::Application::AppContext.for_game(game_id)

# Start day 1
start_day_command = Heroes::Calendar::StartDay.new(
1,
1,
1
)
Rails.configuration.command_bus.call(start_day_command, metadata)
puts "📅 1 Day started"

# Build Dwelling
dwelling_id = "cecc4307-e940-4ef2-8436-80c475729938"
creature_id = "angel"
cost_per_troop = Heroes::SharedKernel::Resources::Cost.resources([ :GOLD, 3000 ], [ :GEM, 1 ])
build_dwelling_command = Heroes::CreatureRecruitment::BuildDwelling.new(
dwelling_id,
creature_id,
cost_per_troop
)
Rails.configuration.command_bus.call(build_dwelling_command, metadata)
puts "🏠 Dwelling built with ID: #{dwelling_id}"

# Increase Available Creatures
increase_creatures_command = Heroes::CreatureRecruitment::IncreaseAvailableCreatures.new(
dwelling_id,
creature_id,
10
)
Rails.configuration.command_bus.call(increase_creatures_command, metadata)
puts "👼 Increased available creatures by 10"

puts "✅ Development seed completed successfully!"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup
super
@dwelling_id = "portal_of_glory"
@creature_id = "angel"
@cost_per_troop = Heroes::SharedKernel::Resources::Cost.resources([ :GOLD, 3000 ], [ :CRYSTAL, 1 ])
@cost_per_troop = Heroes::SharedKernel::Resources::Cost.resources([ :GOLD, 3000 ], [ :GEM, 1 ])
end

def test_given_not_built_dwelling_when_build_dwelling_then_dwelling_built
Expand Down

0 comments on commit 61e4539

Please sign in to comment.