Skip to content

Commit

Permalink
add release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
berlingoqc committed May 2, 2024
1 parent ae6a8d2 commit da6cb22
Show file tree
Hide file tree
Showing 29 changed files with 767 additions and 408 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish to GitHub Pages

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v1
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
#- uses: actions-rs/toolchain@v1
# with:
# toolchain: nightly-2022-04-13
# override: true
- name: Generate website
run: ./build install_web_dependency && ./build build_web_release
- name: Publish generated content to GitHub Pages
uses: tsunematsu21/actions-publish-gh-pages@v1.0.2
with:
dir: website/
branch: gh-pages
token: ${{ secrets.ACCESS_TOKEN }}
#release_dev:
# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v2
# - name: rustup
# run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && rustup default nightly-2022-04-13 && cargo install --force cargo-make && cd game && cargo make build-native
# - name: Create release folder
# run: mkdir -p release && cp ./game/target/debug/cod-zombie-2d-clone ./release
# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: "latest"
# prerelease: true
# title: "Development Build macos"
# files: |
# ./release/*
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
**/public/*.wasm
**/public/assets/
*generated.ldtk
Cargo.lock
Cargo.lock

website/wasm*
website/assets
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Zombie roguelike

The goal is to create an open-source 2d cod zombie with roguelike mechanics

* [game in web browser](https://berlingoqc.github.io/public/cod-zombie-2d-clone/)
37 changes: 37 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash


CARGO_TARGET=./target
CARGO_WEB_TARGET=./target_wasm32


function install_web_dependency {
export CARGO_TARGET_DIR=$CARGO_WEB_TARGET

rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
}

function build_web {
export CARGO_TARGET_DIR=$CARGO_WEB_TARGET

cargo build --example map_preview --target wasm32-unknown-unknown --features bevy_ecs_tilemap/atlas
wasm-bindgen --out-dir ./website/ --out-name wasm --target web $CARGO_WEB_TARGET/wasm32-unknown-unknown/debug/examples/map_preview.wasm

cp -r ./assets ./website/
}

function build_web_release {
export CARGO_TARGET_DIR=$CARGO_WEB_TARGET

cargo build --example map_preview --target wasm32-unknown-unknown --features bevy_ecs_tilemap/atlas --release
wasm-bindgen --out-dir ./website/ --out-name wasm --target web $CARGO_WEB_TARGET/wasm32-unknown-unknown/release/examples/map_preview.wasm

cp -r ./assets ./website/
}




command=$1; shift;
$command "$@"
10 changes: 3 additions & 7 deletions crates/map/src/generation/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

use std::ops::RangeInclusive;

use bevy::prelude::Resource;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum MapGenerationMode {
Expand All @@ -11,7 +10,6 @@ pub enum MapGenerationMode {

#[derive(Debug, Resource, Serialize, Deserialize)]
pub struct MapGenerationConfig {

pub map_path: String,

pub seed: i32,
Expand All @@ -26,18 +24,17 @@ pub struct MapGenerationConfig {

impl Default for MapGenerationConfig {
fn default() -> Self {
Self {
Self {
seed: 1,
max_width: 1000,
max_heigth: 1000,
map_path: "".into(),
max_room: 10,
mode: MapGenerationMode::Basic
mode: MapGenerationMode::Basic,
}
}
}


impl MapGenerationConfig {
pub fn get_range_x(&self, my_size: i32) -> RangeInclusive<i32> {
-self.max_width..=(self.max_width - my_size)
Expand All @@ -46,5 +43,4 @@ impl MapGenerationConfig {
pub fn get_range_y(&self, my_size: i32) -> RangeInclusive<i32> {
-self.max_heigth..=(self.max_heigth - my_size)
}

}
71 changes: 25 additions & 46 deletions crates/map/src/generation/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use super::{config::MapGenerationConfig, entity::location::EntityLocations};

use std::{fmt::Display, rc::Rc, usize};
Expand All @@ -7,21 +6,19 @@ use std::{fmt::Display, rc::Rc, usize};

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Side {
N,
S,
W,
E,
N,
S,
W,
E,
}

impl Side {


pub fn get_opposite(&self) -> Self {
match self {
Side::N => Side::S,
Side::S => Side::N,
Side::W => Side::E,
Side::E => Side::W
Side::E => Side::W,
}
}

Expand All @@ -30,25 +27,22 @@ impl Side {
Side::N => "n",
Side::E => "e",
Side::S => "s",
Side::W => "w"
Side::W => "w",
}
}

pub fn get_factor(&self) -> i32 {
match self {
Side::N | Side::W => -1,
Side::S | Side::E => 1,

}
}

pub fn is_opposite(&self, other: Side) -> bool {
other == self.get_opposite()
}

}


#[derive(Clone, Debug, PartialEq)]
pub enum LevelType {
Spawn,
Expand All @@ -61,32 +55,31 @@ pub struct Connection {
pub size: usize,
pub side: Side,
pub starting_at: usize,

//pub level_iid: String,
pub level_id: String,
pub compatiable_levels: Vec<(String, usize)>,

//pub to: Option<ConnectionTo>,
}

impl Display for Connection {

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "side={:?} starting_at={} size={}", self.size, self.starting_at, self.size)
write!(
f,
"side={:?} starting_at={} size={}",
self.size, self.starting_at, self.size
)
}
}

impl Connection {

fn are_matching(&self, other: &Connection) -> bool {
self.side.is_opposite(other.side) &&
self.starting_at == other.starting_at &&
self.size == other.size
self.side.is_opposite(other.side)
&& self.starting_at == other.starting_at
&& self.size == other.size
}
}



#[derive(Debug, Clone)]
pub struct AvailableLevel {
// identifier of the original level
Expand All @@ -105,12 +98,11 @@ pub struct AvailableLevel {

pub connections: Vec<Connection>,

pub entity_locations: EntityLocations
pub entity_locations: EntityLocations,
}

pub type AvailableLevels = Vec<Rc<AvailableLevel>>;


pub fn scan_width_side(
connections: &mut Vec<Connection>,
index: &mut usize,
Expand All @@ -131,7 +123,7 @@ pub fn scan_width_side(
size += 1;
}

connections.push(Connection {
connections.push(Connection {
index: *index,
size,
side: side.clone(),
Expand All @@ -141,7 +133,7 @@ pub fn scan_width_side(
});

*index = *index + 1;

i += size;
} else {
i += 1;
Expand Down Expand Up @@ -169,7 +161,7 @@ pub fn scan_height_side(
size += 1;
}

connections.push(Connection {
connections.push(Connection {
index: *index,
size,
side: side.clone(),
Expand All @@ -185,50 +177,41 @@ pub fn scan_height_side(
i += 1;
}
}

}



pub fn populate_level_connections(available_levels: &mut Vec<AvailableLevel>) {

let mut to_add_elements: Vec<(usize, usize, (AvailableLevel, usize))> = vec![];

let mut i = 0;
while i < available_levels.len() {
let mut y = 0;

while y < available_levels[i].connections.len() {

let level = &available_levels[i];
let connection = level.connections.get(y).unwrap();

let mut ii = 1;

while ii + i < available_levels.len() {

let mut yy = 0;

if available_levels[ii + i].level_type == LevelType::Spawn {
continue;
}

while yy < available_levels[ii + i].connections.len() {


let other_level = &available_levels[ii + i];

let other_connection = other_level.connections.get(yy).unwrap();

if connection.are_matching(&other_connection) {

//if other_level.level_type != LevelType::Spawn {
to_add_elements.push((i, y, (available_levels[ii + i].clone(), yy)));
to_add_elements.push((i, y, (available_levels[ii + i].clone(), yy)));
//}

// adding otherlevel to add to level
//if level.level_type != LevelType::Spawn {
to_add_elements.push((i + ii, yy, (available_levels[i].clone(), y)));
to_add_elements.push((i + ii, yy, (available_levels[i].clone(), y)));
//}
}

Expand All @@ -237,20 +220,20 @@ pub fn populate_level_connections(available_levels: &mut Vec<AvailableLevel>) {

ii += 1;
}

y += 1;
}

i += 1;
}

for to_add in to_add_elements {
available_levels[to_add.0].connections[to_add.1].compatiable_levels.push((to_add.2.0.level_id.clone(), to_add.2.1));
available_levels[to_add.0].connections[to_add.1]
.compatiable_levels
.push((to_add.2 .0.level_id.clone(), to_add.2 .1));
}

}


pub struct MapGenerationContext {
pub tile_size: (i32, i32),
pub level_size: (i32, i32),
Expand All @@ -268,13 +251,9 @@ pub struct MapGenerationData {
}

impl MapGenerationData {

pub fn from_context(context: &MapGenerationContext) -> Self {
Self {
rng: rand::rngs::StdRng::seed_from_u64(context.config.seed as u64),
}
}

}


Loading

0 comments on commit da6cb22

Please sign in to comment.