some progress towards story and start human rewrite
This commit is contained in:
parent
85b3f6315b
commit
b8cf5e24f6
13 changed files with 172 additions and 49 deletions
|
|
@ -4,10 +4,13 @@ import "globals" for Globals
|
|||
import "blocks/resources" for Resources
|
||||
import "math/stringUtil" for StringUtil
|
||||
import "blocks/human/human" for Human
|
||||
import "luxe: containers" for Lists
|
||||
import "blocks/narrative/diary/diary" for Diary
|
||||
import "blocks/narrative/progress/progress" for Progress
|
||||
|
||||
class Adventures{
|
||||
planning{_planning}
|
||||
max_distance{_max_distance}
|
||||
class AdventureManager{
|
||||
planning : Observable {_planning}
|
||||
max_distance : Num {_max_distance}
|
||||
|
||||
construct new(){
|
||||
_planning = Observable.new()
|
||||
|
|
@ -31,7 +34,6 @@ class Adventures{
|
|||
System.print("Tried to dispatch adventure, but none is planned")
|
||||
return
|
||||
}
|
||||
System.print("Dispatching adventure \"%(adventure)\"")
|
||||
|
||||
adventure.setup()
|
||||
adventure.adventurers.each{|human|
|
||||
|
|
@ -41,13 +43,29 @@ class Adventures{
|
|||
adventure.resources.list().each{|resource|
|
||||
_game.resources.remove(resource["base_name"], resource["amount"])
|
||||
}
|
||||
System.print("Dispatching adventure \"%(adventure)\"")
|
||||
_in_progress.add(adventure)
|
||||
_planning.value = null
|
||||
}
|
||||
|
||||
arrive(adventure: Adventure){
|
||||
Lists.remove(_in_progress, adventure)
|
||||
//bring resources back into main storage
|
||||
adventure.resources.list().each{|resource|
|
||||
_game.resources.add(resource["base_name"], resource["amount"])
|
||||
}
|
||||
adventure.adventurers.each{|adventurer|
|
||||
Human.set_active(adventurer, true)
|
||||
}
|
||||
System.print("Adventure arrived \"%(adventure)\"")
|
||||
}
|
||||
|
||||
tick(){
|
||||
//check some stuff that needs to be checked from time to time
|
||||
//once per second/minute/whatever should be enough
|
||||
_in_progress.each{|adventure : Adventure|
|
||||
adventure.tick(this)
|
||||
}
|
||||
}
|
||||
|
||||
new_or_current(){
|
||||
|
|
@ -90,14 +108,24 @@ class Adventure{
|
|||
}
|
||||
|
||||
setup(){
|
||||
_resources.removeEmpty()
|
||||
}
|
||||
|
||||
tick(manager : AdventureManager){
|
||||
//generate what happens on the day
|
||||
var dayData = Progress.progress(this)
|
||||
//make everyone (try to) write a diary entry about it
|
||||
adventurers.each{|adventurer|
|
||||
Diary.write(adventurer, dayData)
|
||||
}
|
||||
if(dayData["arrive"]) manager.arrive(this)
|
||||
}
|
||||
|
||||
add_adventurer(adventurer){
|
||||
_adventurers.add(adventurer)
|
||||
}
|
||||
|
||||
add_resource(resource){
|
||||
_resources.add(resource)
|
||||
add_resource(resource, amount){
|
||||
_resources.add(resource, amount)
|
||||
}
|
||||
}
|
||||
66
Luxe/blocks/human.wren
Normal file
66
Luxe/blocks/human.wren
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import "luxe: world" for Entity, Transform, Sprite
|
||||
import "Globals" for Globals
|
||||
import "luxe: containers" for Lists
|
||||
import "math/observable" for Observable
|
||||
import "math/vector" for Vector
|
||||
|
||||
class Human{
|
||||
active{_active}
|
||||
active=(value){
|
||||
_active = value
|
||||
if(!__activeHumans) __activeHumans = Observable.new([])
|
||||
if(value){
|
||||
System.print(Globals)
|
||||
show()
|
||||
_changeToken = __activeHumans.on_change{|x| update()}
|
||||
__activeHumans.value.add(this)
|
||||
__activeHumans.emit()
|
||||
} else {
|
||||
hide()
|
||||
_changeToken.discard()
|
||||
Lists.remove(__activeHumans.value, this)
|
||||
__activeHumans.emit()
|
||||
}
|
||||
}
|
||||
name{_name}
|
||||
name=(value){
|
||||
_name = value
|
||||
}
|
||||
adventure_count{_adventure_count}
|
||||
entity{_entity}
|
||||
color=(value){
|
||||
_color = value
|
||||
}
|
||||
|
||||
construct new(){
|
||||
_active = false
|
||||
_name = "unnamed"
|
||||
_adventure_count = 0
|
||||
color = [1, 1, 1, 1]
|
||||
}
|
||||
|
||||
show(){
|
||||
System.print(Globals)
|
||||
_entity = Entity.create(Globals["Game"].app.world, name)
|
||||
Transform.create(_entity)
|
||||
Sprite.create(_entity, _material, 10, 12)
|
||||
Sprite.set_color(_entity, _color.r, _color.g, _color.b, _color.a)
|
||||
}
|
||||
|
||||
hide(){
|
||||
Entity.destroy(_entity)
|
||||
}
|
||||
|
||||
update(){
|
||||
var index = __activeHumans.indexOf(this)
|
||||
var pos = PlayerStart + PlayerSize / 2 + PlayerSize * index
|
||||
Transform.set_pos(_entity, pos.x, pos.y)
|
||||
}
|
||||
|
||||
dispose(){
|
||||
active = false
|
||||
}
|
||||
}
|
||||
|
||||
var PlayerStart:Vector = Vector.new(26, 89)
|
||||
var PlayerSize:Vector = Vector.new(10, 12)
|
||||
|
|
@ -14,7 +14,6 @@ modifier = {
|
|||
//todo: turn this into a implicit number via references from adventure list
|
||||
//todo: make this int?
|
||||
{ name="adventure_count" type="number" default=0 }
|
||||
{ name="diary" type="id32" default="{}" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,6 @@ import "luxe: world" for Block
|
|||
_name = "unnamed"
|
||||
_color = [1, 0, 0, 1]
|
||||
_adventure_count = 0
|
||||
_diary = "{}"
|
||||
} //new
|
||||
|
||||
active { _active }
|
||||
|
|
@ -175,9 +174,6 @@ import "luxe: world" for Block
|
|||
adventure_count { _adventure_count }
|
||||
adventure_count=(vvv) { _adventure_count = vvv }
|
||||
|
||||
diary { _diary }
|
||||
diary=(vvv) { _diary = vvv }
|
||||
|
||||
} //ModifierData
|
||||
|
||||
//`blocks/human/human > data` compilers
|
||||
|
|
@ -199,8 +195,6 @@ import "luxe: world" for Block
|
|||
|
||||
size = size + 8 // adventure_count
|
||||
|
||||
size = size + 4 // diary
|
||||
|
||||
size = size + 0
|
||||
|
||||
return size
|
||||
|
|
@ -217,7 +211,6 @@ import "luxe: world" for Block
|
|||
"name": false,
|
||||
"color": false,
|
||||
"adventure_count": false,
|
||||
"diary": false,
|
||||
}
|
||||
for(element in elements) {
|
||||
var instance = element.value
|
||||
|
|
@ -264,18 +257,13 @@ import "luxe: world" for Block
|
|||
out.write_float64(adventure_count)
|
||||
|
||||
|
||||
var diary = instance["diary"]
|
||||
if(diary == null) diary = "{}"
|
||||
out.write_uint32((diary && diary != "") ? compiler.string.hash(diary) : 0)
|
||||
|
||||
|
||||
return out
|
||||
|
||||
} //write
|
||||
|
||||
bytes_count_block() {
|
||||
|
||||
return 84
|
||||
return 72
|
||||
|
||||
} //bytes_count_block
|
||||
|
||||
|
|
@ -285,7 +273,7 @@ import "luxe: world" for Block
|
|||
out.write_uint32(compiler.string.hash("blocks/human/human > data"))
|
||||
|
||||
//fields count
|
||||
out.write_int32(5)
|
||||
out.write_int32(4)
|
||||
|
||||
// active
|
||||
out.write_uint32(compiler.string.hash("active"))
|
||||
|
|
@ -318,13 +306,6 @@ import "luxe: world" for Block
|
|||
out.write_float64(adventure_count_default)
|
||||
|
||||
|
||||
// diary
|
||||
out.write_uint32(compiler.string.hash("diary"))
|
||||
out.write_uint32(2729592961) //type id32
|
||||
var diary_default = "{}"
|
||||
out.write_uint32((diary_default && diary_default != "") ? compiler.string.hash(diary_default) : 0)
|
||||
|
||||
|
||||
} //write_block
|
||||
|
||||
write(instance) {
|
||||
|
|
@ -363,7 +344,6 @@ import "luxe: world" for Block
|
|||
Block.add(_block, "name", "id32", "unnamed")
|
||||
Block.add(_block, "color", "float4", [1, 0, 0, 1])
|
||||
Block.add(_block, "adventure_count", "number", 0)
|
||||
Block.add(_block, "diary", "id32", "{}")
|
||||
Block.set_type(_block, "blocks/human/human > data")
|
||||
} //new
|
||||
|
||||
|
|
@ -378,8 +358,6 @@ import "luxe: world" for Block
|
|||
color=(v) { Block.set(_block, "color", _slot, v) }
|
||||
adventure_count { Block.get(_block, "adventure_count", _slot) }
|
||||
adventure_count=(v) { Block.set(_block, "adventure_count", _slot, v) }
|
||||
diary { Block.get(_block, "diary", _slot) }
|
||||
diary=(v) { Block.set(_block, "diary", _slot, v) }
|
||||
slot { _slot }
|
||||
entity { Block.get_handle(_block, _slot) }
|
||||
block_set_slot(value) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import "luxe: input" for Input, MouseButton
|
|||
//User facing API
|
||||
//This is what the user of your modifier will interact with
|
||||
class Human {
|
||||
|
||||
static create(entity) { Modifiers.create(This, entity) }
|
||||
static destroy(entity) { Modifiers.destroy(This, entity) }
|
||||
static has(entity) { Modifiers.has(This, entity) }
|
||||
|
|
@ -72,9 +71,11 @@ class HumanSystem is ModifierSystem {
|
|||
player_start{[26, 89]}
|
||||
player_size{[10, 12]}
|
||||
|
||||
dictionaries{_dictionaries}
|
||||
|
||||
construct new() {
|
||||
//called when your system is first created.
|
||||
|
||||
_dictionaries = {}
|
||||
}
|
||||
|
||||
init(world) {
|
||||
|
|
|
|||
11
Luxe/blocks/narrative/diary/diary.wren
Normal file
11
Luxe/blocks/narrative/diary/diary.wren
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
|
||||
class Diary{
|
||||
|
||||
static write(human : int, events : Map) : String{
|
||||
var entry = "We had nice travels and found a dog!"
|
||||
//todo: add to diary data
|
||||
}
|
||||
|
||||
}
|
||||
15
Luxe/blocks/narrative/progress/progress.wren
Normal file
15
Luxe/blocks/narrative/progress/progress.wren
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "blocks/adventures" for Adventure
|
||||
import "globals" for Globals
|
||||
|
||||
class Progress{
|
||||
|
||||
static progress(adventure : Adventure) : Map{
|
||||
adventure.add_resource("dog", 1)
|
||||
var data = {}
|
||||
data["arrive"] = true
|
||||
data["found"] = []
|
||||
data["found"].add({"thing":"dog", "amount":1})
|
||||
data["date"] = Globals["Game"].time.day
|
||||
return data
|
||||
}
|
||||
}
|
||||
26
Luxe/blocks/narrative/time.wren
Normal file
26
Luxe/blocks/narrative/time.wren
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import "math/event" for Event
|
||||
|
||||
class Time{
|
||||
day:Num {_day}
|
||||
onIncrease:Event {_onIncrease}
|
||||
|
||||
construct new(){
|
||||
_day = 0
|
||||
_onIncrease = Event.new()
|
||||
}
|
||||
|
||||
increase(){
|
||||
increase(1)
|
||||
}
|
||||
|
||||
increase(amount: Num){
|
||||
_day = _day + amount
|
||||
for(i in 1..amount){
|
||||
_onIncrease.emit([])
|
||||
}
|
||||
}
|
||||
|
||||
set(day: Num){
|
||||
_day = day
|
||||
}
|
||||
}
|
||||
|
|
@ -43,7 +43,6 @@ class UiAdventure{
|
|||
construct new(ent, ui){
|
||||
_ent = ent
|
||||
_ui = ui
|
||||
|
||||
_game = Globals["Game"]
|
||||
_page = Observable.new(UiAdventure.direction)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ import "math/rect" for AABB
|
|||
import "math/util" for Util
|
||||
import "math/observable" for Observable
|
||||
import "blocks/tooltip" for Tooltip
|
||||
import "blocks/human/human" for Human
|
||||
import "blocks/human" for Human
|
||||
import "blocks/resources" for Resources
|
||||
import "blocks/adventures" for Adventures
|
||||
import "blocks/adventures" for AdventureManager
|
||||
import "blocks/narrative/time" for Time
|
||||
|
||||
class Game is Ready {
|
||||
construct ready() {
|
||||
|
|
@ -27,7 +28,8 @@ class Game is Ready {
|
|||
Globals["Game"] = this
|
||||
|
||||
_focus = Observable.new()
|
||||
_adventures = Adventures.new()
|
||||
_adventures = AdventureManager.new()
|
||||
_time = Time.new()
|
||||
|
||||
app = App.new()
|
||||
_resources = Resources.new()
|
||||
|
|
@ -41,7 +43,7 @@ class Game is Ready {
|
|||
|
||||
} //ready
|
||||
|
||||
tick(delta) {
|
||||
tick(delta: Num) {
|
||||
Globals["Delta"] = delta
|
||||
|
||||
var mouse_pos = Vector.new(Input.mouse_x(), Input.mouse_y())
|
||||
|
|
@ -52,7 +54,6 @@ class Game is Ready {
|
|||
ui_mouse = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y)
|
||||
Globals["UiMouse"] = ui_mouse
|
||||
|
||||
|
||||
DrawDebug.commit()
|
||||
_tooltip.tick()
|
||||
_adventures.tick()
|
||||
|
|
@ -92,15 +93,17 @@ class Game is Ready {
|
|||
}
|
||||
|
||||
create_human(){
|
||||
var human = Entity.create(app.world, "human")
|
||||
Human.create(human)
|
||||
Human.set_color(human, Util.hsv(RandomInst.float(), 0.5, 1))
|
||||
|
||||
var human: Human = Human.new()
|
||||
human.color = Util.hsv(RandomInst.float(), 0.5, 1)
|
||||
var names = Assets.lx("assets/names.lx")
|
||||
var name = names[RandomInst.int(0, names.count)]
|
||||
Human.set_name(human, name)
|
||||
human.name = name
|
||||
Globals["wee"]=false
|
||||
System.print(Globals)
|
||||
human.active = true
|
||||
}
|
||||
|
||||
time{_time}
|
||||
focus{_focus}
|
||||
adventures{_adventures}
|
||||
resources{_resources}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ class WordSequence is Sequence{
|
|||
if(!iterator) iterator = [-1, -1, false] //fake value from -1 to -1
|
||||
if(iterator[1] >= _string.count-1) return false //abort when at end
|
||||
var start = iterator[1]+1
|
||||
System.print(_string.codePointAt_(start))
|
||||
var is_word = StringUtil.is_letter(_string[start])
|
||||
var end = start + 1
|
||||
//count up until you find something thats not a word/separator depending on what the first letter was
|
||||
|
|
|
|||
|
|
@ -109,15 +109,12 @@ class Util{
|
|||
class Actions{
|
||||
|
||||
static actions{
|
||||
System.print(__actions)
|
||||
if(!__actions) __actions = []
|
||||
System.print(__actions)
|
||||
return __actions
|
||||
}
|
||||
|
||||
static queue(fn){
|
||||
actions.add(fn)
|
||||
System.print("actions are %(actions)")
|
||||
}
|
||||
|
||||
static execute(){
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
modules = {
|
||||
luxe = "2020.3.2"
|
||||
luxe = "2020.3.4"
|
||||
luxe-agent = "2020.3.4"
|
||||
} //modules
|
||||
|
|
|
|||
Loading…
Reference in a new issue