Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
OrbGame
Commits
b3a967db
Commit
b3a967db
authored
Jan 21, 2018
by
Florian Blasius
🤘
Browse files
Implemet game builder. Adjust main and adventure example.
parent
c449e296
Changes
7
Hide whitespace changes
Inline
Side-by-side
examples/adventure.rs
View file @
b3a967db
...
...
@@ -2,9 +2,10 @@ extern crate orbgame;
use
std
::
env
;
use
orbgame
::
Game
;
use
orbgame
::
Game
Builder
;
fn
main
()
{
Game
::
from_toml
(
"examples/adventure/game.toml"
)
.exec
();
let
args
:
Vec
<
String
>
=
env
::
args
()
.collect
();
let
game_builder
=
GameBuilder
::
new
(
"examples/adventure/game.ron"
);
game_builder
.build
()
.expect
(
"Could not load game"
)
.exec
();
}
\ No newline at end of file
examples/adventure/game.ron
View file @
b3a967db
...
...
@@ -3,4 +3,5 @@ Game (
width: 800,
height: 600,
target_fps: 60,
theme: "ui.css",
)
\ No newline at end of file
src/game.rs
View file @
b3a967db
...
...
@@ -6,13 +6,12 @@
use
std
::
fs
::
File
;
// use ron::value::Value;
use
ron
;
use
ron
::
value
::
Value
;
use
ron
::
de
::
from_reader
;
use
orbtk
::{
Rect
,
Window
};
// use orbtk::{Place, Rect, Window};
//
use super::{ScriptEngine
, Stage
};
use
super
::{
ScriptEngine
};
#[derive(Clone,
Debug,
Deserialize,
Default)]
#[serde(rename
=
"Game"
)]
...
...
@@ -20,17 +19,14 @@ pub struct Config {
pub
title
:
String
,
pub
width
:
u32
,
pub
height
:
u32
,
pub
target_fps
:
u32
pub
target_fps
:
u32
,
pub
theme
:
String
,
}
impl
Config
{
pub
fn
from_ron
(
path
:
&
str
)
->
ron
::
de
::
Result
<
Config
>
{
from_reader
(
File
::
open
(
&
path
)
.expect
(
"Failed opening file"
))
}
}
pub
struct
Game
{
window
:
Window
,
target_fps
:
u32
,
script_engine
:
ScriptEngine
,
}
impl
Game
{
...
...
@@ -38,16 +34,7 @@ impl Game {
Game
{
window
:
Window
::
new
(
Rect
::
new
(
0
,
0
,
config
.width
,
config
.height
),
&
config
.title
),
target_fps
:
config
.target_fps
,
}
}
pub
fn
from_ron
(
path
:
&
str
)
->
Result
<
Game
,
String
>
{
let
config
=
Config
::
from_ron
(
path
);
println!
(
"{:?}"
,
config
);
if
let
Ok
(
config
)
=
Config
::
from_ron
(
path
)
{
return
Ok
(
Game
::
from_config
(
&
config
))
}
else
{
Err
(
String
::
from
(
"Cloud not load game"
))
script_engine
:
ScriptEngine
::
new
(),
}
}
...
...
src/game_builder.rs
0 → 100644
View file @
b3a967db
use
std
::
fs
::
File
;
use
ron
;
use
ron
::
de
::
from_reader
;
use
game
::{
Config
,
Game
};
pub
struct
GameBuilder
{
path
:
String
,
}
impl
GameBuilder
{
pub
fn
new
(
path
:
&
str
)
->
Self
{
GameBuilder
{
path
:
String
::
from
(
path
)
}
}
pub
fn
build
(
&
self
)
->
Result
<
Game
,
String
>
{
if
let
Ok
(
file
)
=
File
::
open
(
&
self
.path
)
{
let
config
:
ron
::
de
::
Result
<
Config
>
=
from_reader
(
file
);
if
let
Ok
(
config
)
=
config
{
return
Ok
(
Game
::
from_config
(
&
config
))
}
else
{
return
Err
(
String
::
from
(
"Could not parse game file."
))
}
}
Err
(
String
::
from
(
"Could not load game file."
))
}
}
\ No newline at end of file
src/lib.rs
View file @
b3a967db
...
...
@@ -49,17 +49,19 @@ static HEIGHT_KEY: &str = "height";
// pub use self::camera::*;
// pub use self::entity::*;
pub
use
self
::
game_builder
::
*
;
pub
use
self
::
game
::
*
;
// pub use self::tile_map::*;
//
pub use self::script_engine::ScriptEngine;
pub
use
self
::
script_engine
::
ScriptEngine
;
// pub use self::sprite::Sprite;
// pub use self::stage::*;
// mod camera;
// mod entity;
mod
game_builder
;
mod
game
;
// mod tile_map;
//
mod script_engine;
mod
script_engine
;
// mod sprite;
// mod stage;
...
...
src/main.rs
View file @
b3a967db
...
...
@@ -2,9 +2,10 @@ extern crate orbgame;
use
std
::
env
;
use
orbgame
::
Game
;
use
orbgame
::
Game
Builder
;
fn
main
()
{
let
args
:
Vec
<
String
>
=
env
::
args
()
.collect
();
Game
::
from_ron
(
&
args
[
1
][
..
])
.expect
(
"Could not load game"
)
.exec
();
let
game_builder
=
GameBuilder
::
new
(
&
args
[
1
][
..
]);
game_builder
.build
()
.expect
(
"Could not load game"
)
.exec
();
}
src/script_engine.rs
View file @
b3a967db
use
rhai
::{
Engine
,
RegisterFn
,
Scope
};
use
sprite
::
Sprite
;
use
entity
::
Entity
;
use
stage
::
Stage
;
//
use sprite::Sprite;
//
use entity::Entity;
//
use stage::Stage;
pub
struct
ScriptEngine
{
inner_engine
:
Engine
,
...
...
@@ -15,9 +15,9 @@ impl ScriptEngine {
let
mut
inner_engine
=
Engine
::
new
();
let
scope
=
Scope
::
new
();
inner_engine
.register_type
::
<
Sprite
>
();
inner_engine
.register_type
::
<
Entity
>
();
inner_engine
.register_type
::
<
Stage
>
();
//
inner_engine.register_type::<Sprite>();
//
inner_engine.register_type::<Entity>();
//
inner_engine.register_type::<Stage>();
ScriptEngine
{
inner_engine
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment