├── resources ├── images │ └── kiwi.png └── fonts │ └── DejaVuSerif.ttf ├── README.md ├── src ├── error.rs ├── scenes │ ├── mod.rs │ ├── menu.rs │ └── level.rs ├── types.rs ├── systems.rs ├── components.rs ├── input.rs ├── util.rs ├── world.rs ├── resources.rs └── main.rs ├── .gitignore ├── Cargo.toml ├── LICENSE-MIT └── LICENSE-APACHE /resources/images/kiwi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggez/game-template/HEAD/resources/images/kiwi.png -------------------------------------------------------------------------------- /resources/fonts/DejaVuSerif.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggez/game-template/HEAD/resources/fonts/DejaVuSerif.ttf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # game-template 2 | 3 | A (not necessarily complete) game template combining [ggez](https://github.com/ggez/ggez/) with another of other useful Rust 4 | gamedev tools: 5 | 6 | * log + fern (logging) 7 | * specs (ECS) 8 | * warmy (resource handling) 9 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | //! Basic error types. 2 | 3 | use ggez; 4 | 5 | #[derive(Debug, Fail)] 6 | #[fail(display = "ggez error: {:?}", err)] 7 | pub struct GgezError { 8 | err: ggez::GameError, 9 | } 10 | 11 | impl From for GgezError { 12 | fn from(err: ggez::GameError) -> Self { 13 | Self { err } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | # Log file 13 | debug.log 14 | -------------------------------------------------------------------------------- /src/scenes/mod.rs: -------------------------------------------------------------------------------- 1 | use ggez_goodies::scene; 2 | 3 | use crate::input; 4 | use crate::world::World; 5 | 6 | pub mod level; 7 | pub mod menu; 8 | 9 | // Shortcuts for our scene type. 10 | pub type Switch = scene::SceneSwitch; 11 | pub type Stack = scene::SceneStack; 12 | // Useless, since you can't impl type aliases. :| 13 | //pub trait Scene = scene::Scene; 14 | -------------------------------------------------------------------------------- /src/types.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | pub use ggez_goodies::Point2; 4 | pub use ggez_goodies::Vector2; 5 | 6 | /// This is not actually used very many places, 7 | /// but is still useful. 8 | #[derive(Debug)] 9 | pub enum Error { 10 | GgezError(ggez::GameError), 11 | } 12 | 13 | impl fmt::Display for Error { 14 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 15 | match *self { 16 | Error::GgezError(ref e) => write!(f, "ggez error: {}", e), 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ggez_game_template" 3 | version = "0.1.0" 4 | authors = ["Simon Heath "] 5 | license = "MIT OR Apache-2.0" 6 | readme = "README.md" 7 | edition = "2018" 8 | 9 | [profile.dev] 10 | opt-level = 1 11 | 12 | 13 | [dependencies] 14 | ggez = "0.5" 15 | ggez-goodies = "0.5" 16 | euclid = {version = "0.19", features=["mint"]} 17 | warmy = "0.11" 18 | log = "0.4" 19 | fern = {version = "0.5", features = ["colored"] } 20 | chrono = "0.4" 21 | specs = "0.14" 22 | specs-derive = "0.4" 23 | -------------------------------------------------------------------------------- /src/systems.rs: -------------------------------------------------------------------------------- 1 | //! specs systems. 2 | use crate::components::*; 3 | use specs::{self, Join}; 4 | 5 | pub struct MovementSystem; 6 | 7 | impl<'a> specs::System<'a> for MovementSystem { 8 | type SystemData = ( 9 | specs::WriteStorage<'a, Position>, 10 | specs::WriteStorage<'a, Motion>, 11 | ); 12 | 13 | fn run(&mut self, (mut pos, mut motion): Self::SystemData) { 14 | // The `.join()` combines multiple components, 15 | // so we only access those entities which have 16 | // both of them. 17 | for (pos, motion) in (&mut pos, &mut motion).join() { 18 | pos.0 += motion.velocity; 19 | motion.velocity += motion.acceleration; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 the ggez developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/components.rs: -------------------------------------------------------------------------------- 1 | use crate::types::*; 2 | 3 | use specs::*; 4 | use specs_derive::*; 5 | 6 | // /////////////////////////////////////////////////////////////////////// 7 | // Components 8 | // /////////////////////////////////////////////////////////////////////// 9 | 10 | /// A position in the game world. 11 | #[derive(Clone, Debug, Component)] 12 | #[storage(VecStorage)] 13 | pub struct Position(pub Point2); 14 | 15 | /// Motion in the game world. 16 | #[derive(Clone, Debug, Component)] 17 | #[storage(VecStorage)] 18 | pub struct Motion { 19 | pub velocity: Vector2, 20 | pub acceleration: Vector2, 21 | } 22 | 23 | /// Just a marker that a particular entity is the player. 24 | #[derive(Clone, Debug, Default, Component)] 25 | #[storage(NullStorage)] 26 | pub struct Player; 27 | 28 | #[derive(Clone, Debug, Default, Component)] 29 | #[storage(VecStorage)] 30 | pub struct Shot { 31 | pub damage: u32, 32 | } 33 | 34 | pub fn register_components(specs_world: &mut World) { 35 | specs_world.register::(); 36 | specs_world.register::(); 37 | specs_world.register::(); 38 | specs_world.register::(); 39 | } 40 | -------------------------------------------------------------------------------- /src/input.rs: -------------------------------------------------------------------------------- 1 | //! Typedefs for input shortcuts. 2 | use ggez::event::*; 3 | use ggez_goodies::input; 4 | 5 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 6 | pub enum Button { 7 | Select, 8 | Back, 9 | Menu, 10 | Quit, 11 | } 12 | 13 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 14 | pub enum Axis { 15 | Vert, 16 | Horz, 17 | } 18 | 19 | pub type Binding = input::InputBinding; 20 | pub type Event = input::InputEffect; 21 | pub type State = input::InputState; 22 | 23 | /// Create the default keybindings for our input state. 24 | pub fn create_input_binding() -> input::InputBinding { 25 | input::InputBinding::new() 26 | .bind_key_to_axis(KeyCode::Up, Axis::Vert, true) 27 | .bind_key_to_axis(KeyCode::Down, Axis::Vert, false) 28 | .bind_key_to_axis(KeyCode::Left, Axis::Horz, false) 29 | .bind_key_to_axis(KeyCode::Right, Axis::Horz, true) 30 | .bind_key_to_button(KeyCode::C, Button::Select) 31 | .bind_key_to_button(KeyCode::X, Button::Back) 32 | .bind_key_to_button(KeyCode::Z, Button::Menu) 33 | .bind_key_to_button(KeyCode::Escape, Button::Quit) 34 | } 35 | -------------------------------------------------------------------------------- /src/util.rs: -------------------------------------------------------------------------------- 1 | /// A couple handy re-exports from Euclid 2 | pub use euclid::point2; 3 | pub use euclid::vec2; 4 | 5 | /// Basic logging setup to log to the console with `fern`. 6 | pub fn setup_logging() { 7 | use fern::colors::{Color, ColoredLevelConfig}; 8 | let colors = ColoredLevelConfig::default() 9 | .info(Color::Green) 10 | .debug(Color::BrightMagenta) 11 | .trace(Color::BrightBlue); 12 | // This sets up a `fern` logger and initializes `log`. 13 | fern::Dispatch::new() 14 | // Formats logs 15 | .format(move |out, message, record| { 16 | out.finish(format_args!( 17 | "[{}][{:<5}][{}] {}", 18 | chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), 19 | colors.color(record.level()), 20 | record.target(), 21 | message 22 | )) 23 | }) 24 | .level(log::LevelFilter::Warn) 25 | // Filter out unnecessary stuff 26 | .level_for("gfx", log::LevelFilter::Off) 27 | // .level_for("walk", log::LevelFilter::Warn) 28 | // Set levels for stuff we care about 29 | .level_for("threething", log::LevelFilter::Trace) 30 | // Hooks up console output. 31 | // env var for outputting to a file? 32 | // Haven't needed it yet! 33 | .chain(std::io::stdout()) 34 | .apply() 35 | .expect("Could not init logging!"); 36 | } 37 | -------------------------------------------------------------------------------- /src/world.rs: -------------------------------------------------------------------------------- 1 | use crate::{components, input, resources, util}; 2 | 3 | use log::*; 4 | use specs::{self, world::Builder}; 5 | use warmy; 6 | 7 | use std::path; 8 | 9 | pub struct World { 10 | pub resources: resources::Store, 11 | pub input: input::State, 12 | pub specs_world: specs::World, 13 | } 14 | 15 | impl World { 16 | pub fn new(resource_dir: &path::Path) -> Self { 17 | // We to bridge the gap between ggez and warmy path 18 | // handling here; ggez assumes its own absolute paths, warmy 19 | // assumes system-absolute paths; so, we make warmy look in 20 | // the specified resource dir (normally 21 | // $CARGO_MANIFEST_DIR/resources) or the ggez default resource 22 | // dir. 23 | // 24 | // TODO: ...though this doesn't SEEM to quite do reloading right, so 25 | // work on it more. 26 | info!("Setting up resource path: {:?}", resource_dir); 27 | let opt = warmy::StoreOpt::default().set_root(resource_dir); 28 | let store = warmy::Store::new(opt) 29 | .expect("Could not create asset store? Does the directory exist?"); 30 | 31 | let mut w = specs::World::new(); 32 | components::register_components(&mut w); 33 | 34 | let mut the_world = Self { 35 | resources: store, 36 | input: input::State::new(), 37 | specs_world: w, 38 | }; 39 | 40 | // Make a test entity. 41 | the_world 42 | .specs_world 43 | .create_entity() 44 | .with(components::Position(util::point2(0.0, 0.0))) 45 | .with(components::Motion { 46 | velocity: util::vec2(1.0, 1.0), 47 | acceleration: util::vec2(0.0, 0.0), 48 | }) 49 | .build(); 50 | 51 | the_world 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/scenes/menu.rs: -------------------------------------------------------------------------------- 1 | use ggez; 2 | use ggez::graphics; 3 | use ggez_goodies::scene; 4 | use log::*; 5 | 6 | use crate::input; 7 | use crate::world::World; 8 | use crate::scenes; 9 | use crate::types::*; 10 | 11 | pub struct MenuScene { 12 | title_text: graphics::Text, 13 | input_text: graphics::Text, 14 | done: bool, 15 | } 16 | 17 | impl MenuScene { 18 | pub fn new(ctx: &mut ggez::Context, _world: &mut World) -> Self { 19 | let font = graphics::Font::new(ctx, "/fonts/DejaVuSerif.ttf").unwrap(); 20 | let title_text = graphics::Text::new(("Main Menu", font, 48.0)); 21 | let input_text = graphics::Text::new(("Press Any Key to Start", font, 20.0)); 22 | 23 | let done = false; 24 | MenuScene { 25 | title_text, 26 | input_text, 27 | done, 28 | } 29 | } 30 | } 31 | 32 | impl scene::Scene for MenuScene { 33 | fn update(&mut self, gameworld: &mut World, ctx: &mut ggez::Context) -> scenes::Switch { 34 | if self.done { 35 | self.done = false; 36 | scene::SceneSwitch::Push(Box::new(scenes::level::LevelScene::new(ctx, gameworld))) 37 | } else { 38 | scene::SceneSwitch::None 39 | } 40 | } 41 | 42 | fn draw(&mut self, _gameworld: &mut World, ctx: &mut ggez::Context) -> ggez::GameResult<()> { 43 | graphics::draw( 44 | ctx, 45 | &self.title_text, 46 | graphics::DrawParam::default().dest(Point2::new(200.0,200.0)), 47 | )?; 48 | graphics::draw( 49 | ctx, 50 | &self.input_text, 51 | graphics::DrawParam::default().dest(Point2::new(200.0,300.0)), 52 | )?; 53 | Ok(()) 54 | } 55 | 56 | fn name(&self) -> &str { 57 | "MenuScene" 58 | } 59 | 60 | fn input(&mut self, _gameworld: &mut World, ev: input::Event, _started: bool) { 61 | debug!("Input: {:?}", ev); 62 | self.done = true; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/resources.rs: -------------------------------------------------------------------------------- 1 | //! Example of integrating ggez types with the `warmy` resource loader. 2 | 3 | use std::path; 4 | 5 | use ggez::{self, graphics}; 6 | use log::*; 7 | use warmy; 8 | 9 | use crate::types::Error; 10 | 11 | /// Again, because `warmy` assumes direct filesystem dirs 12 | /// and ggez assumes all its resources live in a specific 13 | /// (relative) location, we make our own key type here which 14 | /// doesn't get `warmy`'s root path attached to it like its 15 | /// `SimpleKey` types do. 16 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 17 | pub enum Key { 18 | Path(path::PathBuf), 19 | } 20 | 21 | impl From<&path::Path> for Key { 22 | fn from(p: &path::Path) -> Self { 23 | Key::Path(p.to_owned()) 24 | } 25 | } 26 | 27 | impl Key { 28 | pub fn from_path

(p: P) -> Self 29 | where 30 | P: AsRef, 31 | { 32 | Key::Path(p.as_ref().to_owned()) 33 | } 34 | } 35 | 36 | impl warmy::key::Key for Key { 37 | fn prepare_key(self, _root: &path::Path) -> Self { 38 | self 39 | } 40 | } 41 | 42 | /// Store and Storage are different things in `warmy`; the `Store` 43 | /// is what actually stores things, and the `Storage` is I think 44 | /// a handle to it. 45 | pub type Store = warmy::Store; 46 | type Storage = warmy::Storage; 47 | pub type Loaded = warmy::Loaded; 48 | 49 | /// A wrapper for a ggez Image, so we can implement warmy's `Load` trait on it. 50 | #[derive(Debug, Clone)] 51 | pub struct Image(pub graphics::Image); 52 | 53 | /// And, here actually tell Warmy how to load things. 54 | impl warmy::Load for Image { 55 | type Error = Error; 56 | fn load( 57 | key: Key, 58 | _storage: &mut Storage, 59 | ctx: &mut ggez::Context, 60 | ) -> Result, Self::Error> { 61 | debug!("Loading image {:?}", key); 62 | 63 | match key { 64 | Key::Path(path) => graphics::Image::new(ctx, path) 65 | .map(|x| warmy::Loaded::from(Image(x))) 66 | .map_err(|e| Error::GgezError(e)), 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/scenes/level.rs: -------------------------------------------------------------------------------- 1 | use ggez; 2 | use ggez::graphics; 3 | use ggez_goodies::scene; 4 | use log::*; 5 | use specs::{self, Join}; 6 | use warmy; 7 | 8 | use crate::components as c; 9 | use crate::input; 10 | use crate::resources; 11 | use crate::scenes; 12 | use crate::systems::*; 13 | use crate::world::World; 14 | 15 | pub struct LevelScene { 16 | done: bool, 17 | kiwi: warmy::Res, 18 | dispatcher: specs::Dispatcher<'static, 'static>, 19 | } 20 | 21 | impl LevelScene { 22 | pub fn new(ctx: &mut ggez::Context, world: &mut World) -> Self { 23 | let done = false; 24 | let kiwi = world 25 | .resources 26 | .get::(&resources::Key::from_path("/images/kiwi.png"), ctx) 27 | .unwrap(); 28 | 29 | let mut dispatcher = Self::register_systems(); 30 | dispatcher.setup(&mut world.specs_world.res); 31 | 32 | LevelScene { 33 | done, 34 | kiwi, 35 | dispatcher, 36 | } 37 | } 38 | 39 | fn register_systems() -> specs::Dispatcher<'static, 'static> { 40 | specs::DispatcherBuilder::new() 41 | .with(MovementSystem, "sys_movement", &[]) 42 | .build() 43 | } 44 | } 45 | 46 | impl scene::Scene for LevelScene { 47 | fn update(&mut self, gameworld: &mut World, _ctx: &mut ggez::Context) -> scenes::Switch { 48 | self.dispatcher.dispatch(&mut gameworld.specs_world.res); 49 | if self.done { 50 | scene::SceneSwitch::Pop 51 | } else { 52 | scene::SceneSwitch::None 53 | } 54 | } 55 | 56 | fn draw(&mut self, gameworld: &mut World, ctx: &mut ggez::Context) -> ggez::GameResult<()> { 57 | let pos = gameworld.specs_world.read_storage::(); 58 | for p in pos.join() { 59 | graphics::draw( 60 | ctx, 61 | &(self.kiwi.borrow().0), 62 | graphics::DrawParam::default().dest(p.0), 63 | )?; 64 | } 65 | Ok(()) 66 | } 67 | 68 | fn name(&self) -> &str { 69 | "LevelScene" 70 | } 71 | 72 | fn input(&mut self, gameworld: &mut World, ev: input::Event, _started: bool) { 73 | debug!("Input: {:?}", ev); 74 | if gameworld.input.get_button_pressed(input::Button::Menu) { 75 | self.done = true; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | //! Game setup and very basic main loop. 2 | //! All the actual work gets done in the Scene. 3 | 4 | use std::env; 5 | use std::path; 6 | 7 | use ggez::{self, *}; 8 | 9 | mod components; 10 | mod input; 11 | mod resources; 12 | mod scenes; 13 | mod systems; 14 | mod types; 15 | mod util; 16 | mod world; 17 | 18 | struct MainState { 19 | scenes: scenes::Stack, 20 | input_binding: input::Binding, 21 | } 22 | 23 | impl MainState { 24 | fn new(ctx: &mut Context, resource_path: &path::Path) -> Self { 25 | let world = world::World::new(resource_path); 26 | let mut scenestack = scenes::Stack::new(ctx, world); 27 | let initial_scene = Box::new(scenes::menu::MenuScene::new(ctx, &mut scenestack.world)); 28 | scenestack.push(initial_scene); 29 | 30 | Self { 31 | input_binding: input::create_input_binding(), 32 | scenes: scenestack, 33 | } 34 | } 35 | } 36 | 37 | impl event::EventHandler for MainState { 38 | fn update(&mut self, ctx: &mut Context) -> GameResult<()> { 39 | const DESIRED_FPS: u32 = 60; 40 | while timer::check_update_time(ctx, DESIRED_FPS) { 41 | self.scenes.update(ctx); 42 | } 43 | self.scenes.world.resources.sync(ctx); 44 | 45 | Ok(()) 46 | } 47 | 48 | fn draw(&mut self, ctx: &mut Context) -> GameResult<()> { 49 | graphics::clear(ctx, graphics::Color::from((0.0, 0.0, 0.4, 0.0))); 50 | self.scenes.draw(ctx); 51 | graphics::present(ctx) 52 | } 53 | 54 | fn key_down_event( 55 | &mut self, 56 | _ctx: &mut Context, 57 | keycode: event::KeyCode, 58 | _keymod: event::KeyMods, 59 | _repeat: bool, 60 | ) { 61 | if let Some(ev) = self.input_binding.resolve(keycode) { 62 | self.scenes.input(ev, true); 63 | self.scenes.world.input.update_effect(ev, true); 64 | } 65 | } 66 | 67 | fn key_up_event( 68 | &mut self, 69 | _ctx: &mut Context, 70 | keycode: event::KeyCode, 71 | _keymod: event::KeyMods, 72 | ) { 73 | if let Some(ev) = self.input_binding.resolve(keycode) { 74 | self.scenes.input(ev, false); 75 | self.scenes.world.input.update_effect(ev, false); 76 | } 77 | } 78 | } 79 | 80 | fn main() { 81 | util::setup_logging(); 82 | 83 | let resource_dir = if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { 84 | let mut path = path::PathBuf::from(manifest_dir); 85 | path.push("resources"); 86 | path 87 | } else { 88 | path::PathBuf::from("./resources") 89 | }; 90 | println!("Resource dir: {:?}", resource_dir); 91 | 92 | let cb = ContextBuilder::new("game-template", "ggez") 93 | .window_setup(conf::WindowSetup::default().title("game template")) 94 | .window_mode(conf::WindowMode::default().dimensions(800.0, 600.0)) 95 | .add_resource_path(&resource_dir); 96 | let (ctx, ev) = &mut cb.build().unwrap(); 97 | 98 | let state = &mut MainState::new(ctx, &resource_dir); 99 | if let Err(e) = event::run(ctx, ev, state) { 100 | println!("Error encountered: {}", e); 101 | } else { 102 | println!("Game exited cleanly."); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | Limitations under the License. 202 | --------------------------------------------------------------------------------