Compare commits
No commits in common. "a3e22101956cb9410d12ca8d7f1214f400fa0189" and "3aab658b1eac8a4baa527f0a10ef3420b4423c2f" have entirely different histories.
a3e2210195
...
3aab658b1e
8 changed files with 84 additions and 258 deletions
|
|
@ -5,11 +5,7 @@
|
|||
|
||||
"Abyole"
|
||||
"Afua"
|
||||
"Alisha"
|
||||
"Aljoscha"
|
||||
"Amelia"
|
||||
"Ariadne"
|
||||
"Ashley"
|
||||
"Bertine"
|
||||
"Bob"
|
||||
"Bug"
|
||||
|
|
@ -24,16 +20,12 @@
|
|||
"Ida"
|
||||
"Innes"
|
||||
"Irene"
|
||||
"Irina"
|
||||
"Isisa"
|
||||
"Jamie"
|
||||
"Jamison"
|
||||
"Jess"
|
||||
"Jules"
|
||||
"Kabanga"
|
||||
"Karl"
|
||||
"Karo"
|
||||
"Kolja"
|
||||
"Lara"
|
||||
"Laura"
|
||||
"Lauren"
|
||||
|
|
@ -45,16 +37,12 @@
|
|||
"Merryl"
|
||||
"Mii'a"
|
||||
"Niels"
|
||||
"Nils"
|
||||
"Nina"
|
||||
"Nova"
|
||||
"Rami"
|
||||
"Ramona"
|
||||
"Richard"
|
||||
"Rob"
|
||||
"Robin"
|
||||
"Ronja"
|
||||
"Sam"
|
||||
"Sandra"
|
||||
"Simon"
|
||||
"Sironka"
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ import "math/observable" for Observable
|
|||
import "luxe: world" for Entity, Values, Tags
|
||||
import "globals" for Globals
|
||||
import "blocks/resources" for Resources
|
||||
import "math/stringUtil" for StringUtil
|
||||
import "blocks/human/human" for Human
|
||||
|
||||
class Adventures{
|
||||
planning{_planning}
|
||||
|
|
@ -14,41 +12,14 @@ class Adventures{
|
|||
_in_progress = []
|
||||
_archive = []
|
||||
_max_distance = 10
|
||||
_game = Globals["Game"]
|
||||
}
|
||||
|
||||
plan_new(){
|
||||
System.print("Start planning new Adventure")
|
||||
var adventure = Adventure.new()
|
||||
adventure.distance = 2
|
||||
_planning.value = adventure
|
||||
return adventure
|
||||
}
|
||||
|
||||
dispatch(){
|
||||
var adventure = _planning.value
|
||||
if(!adventure){
|
||||
System.print("Tried to dispatch adventure, but none is planned")
|
||||
return
|
||||
}
|
||||
System.print("Dispatching adventure \"%(adventure)\"")
|
||||
|
||||
adventure.setup()
|
||||
adventure.adventurers.each{|human|
|
||||
Human.set_active(human, false)
|
||||
}
|
||||
adventure.resources.list().each{|resource|
|
||||
_game.resources.remove(resource["base_name"], resource["amount"])
|
||||
}
|
||||
_in_progress.add(adventure)
|
||||
_planning.value = null
|
||||
}
|
||||
|
||||
tick(){
|
||||
//check some stuff that needs to be checked from time to time
|
||||
//once per second/minute/whatever should be enough
|
||||
}
|
||||
|
||||
new_or_current(){
|
||||
if(_planning.value) return _planning.value
|
||||
return plan_new()
|
||||
|
|
@ -73,12 +44,6 @@ class Adventure{
|
|||
distance{_distance}
|
||||
distance=(dist){_distance = dist}
|
||||
|
||||
toString{
|
||||
return "%(adventurers.map{|id| Human.get_name(id)}.toList)"+
|
||||
" travelling %(distance)km towards %(StringUtil.direction(direction))"+
|
||||
" with %(resources.list().map{|resource| "%(resource["amount"]) %(resource["name"])"}.toList)"
|
||||
}
|
||||
|
||||
construct new(){
|
||||
_adventurers = []
|
||||
_resources = Resources.new()
|
||||
|
|
@ -88,10 +53,6 @@ class Adventure{
|
|||
_distance = 0
|
||||
}
|
||||
|
||||
setup(){
|
||||
|
||||
}
|
||||
|
||||
add_adventurer(adventurer){
|
||||
_adventurers.add(adventurer)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,18 +50,6 @@ class Human {
|
|||
data.adventure_count = data.adventure_count + 1
|
||||
}
|
||||
|
||||
static get_active(entity){
|
||||
if(entity == 0 || !entity) return null
|
||||
var data = Modifiers.get(This, entity)
|
||||
return data.active
|
||||
}
|
||||
|
||||
static set_active(entity, active){
|
||||
if(entity == 0 || !entity) return null
|
||||
var data = Modifiers.get(This, entity)
|
||||
data.active = active
|
||||
}
|
||||
|
||||
} //Human
|
||||
|
||||
//Your modifier system implementation.
|
||||
|
|
@ -126,28 +114,28 @@ class HumanSystem is ModifierSystem {
|
|||
game.focus.value = _hoverEnt
|
||||
}
|
||||
}
|
||||
|
||||
update() //optimisation: consider running this less often
|
||||
} //tick
|
||||
|
||||
update(){
|
||||
if(World.tag_has(_world, "edit")) return
|
||||
|
||||
var size = Vector.new(player_size)
|
||||
var pos = Vector.new(player_start) + size / 2
|
||||
each {|entity, data|
|
||||
if(!data.active){
|
||||
if(Transform.has(entity))Transform.destroy(entity)
|
||||
if(Sprite.has(entity))Sprite.destroy(entity)
|
||||
} else {
|
||||
if(!Transform.has(entity)){
|
||||
Transform.create(entity)
|
||||
}
|
||||
if(!Sprite.has(entity)){
|
||||
Sprite.create(entity, _material, 10, 12)
|
||||
Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, data.color.a)
|
||||
}
|
||||
Transform.set_pos(entity, pos.x, pos.y)
|
||||
pos.x = pos.x + size.x
|
||||
Transform.destroy(entity)
|
||||
Sprite.destroy(entity)
|
||||
return
|
||||
}
|
||||
if(!Transform.has(entity)){
|
||||
Transform.create(entity)
|
||||
}
|
||||
if(!Sprite.has(entity)){
|
||||
Sprite.create(entity, _material, 10, 12)
|
||||
Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, data.color.a)
|
||||
}
|
||||
Transform.set_pos(entity, pos.x, pos.y)
|
||||
pos.x = pos.x + size.x
|
||||
}
|
||||
}
|
||||
} //HumanSystem
|
||||
|
|
|
|||
|
|
@ -14,24 +14,19 @@ class Resources is Observable{
|
|||
value_no_update = this
|
||||
}
|
||||
|
||||
toString{
|
||||
return list().map{|resource| "%(resource["amount"]) %(resource["name"])"}.toList.toString
|
||||
}
|
||||
|
||||
list(){
|
||||
//construct map from name and amount
|
||||
var list = _nameList.map{ |res| {"name": res, "amount": _resources[res["name"]]}}.
|
||||
var list = _nameList.map{ |res| {"name": res, "amount": _resources[res["name"]]}}.//<-- butt dot!
|
||||
//filter out the ones without an amount
|
||||
where{ |res| res["amount"] }.
|
||||
toList //toList makes the each work ^^ otherwise the result sequence runs map twice
|
||||
//get correct name and respect plural rules //also this is its own line because each returns void >.>
|
||||
list.each{ |res|
|
||||
var name = res["name"]["name"]
|
||||
var singular = res["amount"] == 1 || res["name"]["alwaysSingular"]
|
||||
res["name"] = singular ? name : StringUtil.plural(name)
|
||||
res["base_name"] = name
|
||||
}
|
||||
|
||||
var name = res["name"]["name"]
|
||||
var singular = res["amount"] == 1 || res["name"]["alwaysSingular"]
|
||||
res["name"] = singular ? name : StringUtil.plural(name)
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,32 @@
|
|||
import "luxe: assets" for Assets, Strings
|
||||
import "luxe: color" for Color
|
||||
import "luxe: containers" for Lists
|
||||
import "luxe: draw" for Draw, PathStyle
|
||||
import "luxe: game" for Frame
|
||||
import "luxe: math" for Math
|
||||
import "luxe: render" for Material, TextAlign
|
||||
import "luxe: ui/control" for Control
|
||||
import "luxe: ui/image" for UIImage
|
||||
import "luxe: ui/label" for UILabel
|
||||
import "luxe: world" for Entity, Transform, UI, UIRenderMode, UIEvent
|
||||
import "luxe: world" for UILayout, UILayoutBehave, UILayoutContain
|
||||
import "luxe: ui/control" for Control
|
||||
import "luxe: ui/label" for UILabel
|
||||
import "luxe: ui/image" for UIImage
|
||||
import "luxe: assets" for Assets, Strings
|
||||
import "luxe: render" for Material, TextAlign
|
||||
import "luxe: color" for Color
|
||||
import "luxe: game" for Frame
|
||||
import "luxe: containers" for Lists
|
||||
import "luxe: math" for Math
|
||||
|
||||
import "blocks/human/human" for Human
|
||||
import "blocks/ui/box" for UIBox
|
||||
import "globals" for Globals
|
||||
import "blocks/ui/clickable" for Clickable
|
||||
import "blocks/ui/compass" for UiCompass
|
||||
import "blocks/ui/image_util" for UiImageUtil
|
||||
import "math/observable" for Observable
|
||||
import "blocks/ui/simple_text" for UISimpleText
|
||||
import "blocks/ui/ui" for Ui
|
||||
import "blocks/ui/slider" for UiSlider
|
||||
import "blocks/ui/box" for UIBox
|
||||
import "blocks/ui/scroll_box" for UiScrollBox
|
||||
import "blocks/ui/compass" for UiCompass
|
||||
import "blocks/ui/info" for UiInfo //this is a cyclic dependency waiting to happen...
|
||||
import "blocks/ui/number_field" for NumberField
|
||||
import "blocks/ui/scroll_box" for UiScrollBox
|
||||
import "blocks/ui/simple_text" for UISimpleText
|
||||
import "blocks/ui/slider" for UiSlider
|
||||
import "blocks/ui/ui" for Ui
|
||||
import "globals" for Globals
|
||||
import "math/event" for MultiListenerToken
|
||||
import "math/math" for M
|
||||
import "math/observable" for Observable
|
||||
import "math/stringUtil" for StringUtil
|
||||
import "math/util" for Util
|
||||
import "math/event" for MultiListenerToken
|
||||
import "blocks/human/human" for Human
|
||||
|
||||
class UiAdventure{
|
||||
root{_root}
|
||||
|
|
@ -36,7 +35,6 @@ class UiAdventure{
|
|||
static people{"people"}
|
||||
static resources{"resources"}
|
||||
static depart{"depart"}
|
||||
static abort{"abort"}
|
||||
|
||||
adventure{_game.adventures.planning} //shortcut to get currently planning adventure (observable)
|
||||
|
||||
|
|
@ -52,25 +50,17 @@ class UiAdventure{
|
|||
|
||||
setup(){
|
||||
var ui_rect = Globals["UiRect"]
|
||||
var game = Globals["Game"]
|
||||
|
||||
_root = Control.create(_ent)
|
||||
Control.set_allow_input(_root, true)
|
||||
Control.set_size(_root, ui_rect.width, ui_rect.height)
|
||||
|
||||
//if no adventure is planned anymore, leave adventure planning ui
|
||||
_game.adventures.planning.on_change{|adventure|
|
||||
if(!adventure){
|
||||
_ui.ui_mode = Ui.Info
|
||||
_page.value = UiAdventure.direction
|
||||
}
|
||||
}
|
||||
|
||||
toolbar()
|
||||
direction()
|
||||
people()
|
||||
resources()
|
||||
depart()
|
||||
abort()
|
||||
}
|
||||
|
||||
toolbar(){
|
||||
|
|
@ -88,7 +78,11 @@ class UiAdventure{
|
|||
_ui.list_button(list, [2, 0], "People") {_page.value = UiAdventure.people}
|
||||
_ui.list_button(list, [4, 0], "Stuff") {_page.value = UiAdventure.resources}
|
||||
_ui.list_button(list, [5, 0], "Depart") {_page.value = UiAdventure.depart}
|
||||
_ui.list_button(list, [0, 0], "Abort") {_page.value = UiAdventure.abort}
|
||||
_ui.list_button(list, [0, 0], "Abort") {
|
||||
_ui.ui_mode = Ui.Info
|
||||
_game.adventures.discard()
|
||||
_page.value = UiAdventure.direction
|
||||
}
|
||||
}
|
||||
|
||||
direction(){
|
||||
|
|
@ -108,6 +102,21 @@ class UiAdventure{
|
|||
Control.set_size(compass, 32, 32)
|
||||
UILayout.set_margin(_ent, compass, 8, 0, 0, 0)
|
||||
var steps = 16 //compass steps
|
||||
var step_names = ["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
|
||||
var full_step_names = step_names.map{|short|
|
||||
var shorts = "NESW"
|
||||
var base_directions = ["north","east","south","west"]
|
||||
if(short.count == 1){
|
||||
return base_directions[shorts.indexOf(short)]
|
||||
} else if(short.count == 2) {
|
||||
return base_directions[shorts.indexOf(short[0])] +
|
||||
base_directions[shorts.indexOf(short[1])]
|
||||
} else { //assume 3
|
||||
return base_directions[shorts.indexOf(short[0])] + "-" +
|
||||
base_directions[shorts.indexOf(short[1])] +
|
||||
base_directions[shorts.indexOf(short[2])]
|
||||
}
|
||||
}.toList
|
||||
|
||||
adventure.on_change(true){|val|
|
||||
if(val == null) return
|
||||
|
|
@ -167,7 +176,7 @@ class UiAdventure{
|
|||
adventure.on_change(true) { |val|
|
||||
if(val == null) return
|
||||
//this stuff does bad things
|
||||
var dir = StringUtil.direction(val.direction)
|
||||
var dir = full_step_names[val.direction]
|
||||
var dist = val.distance
|
||||
UILabel.set_text(text, "%(dist)km\n%(dir)")
|
||||
}
|
||||
|
|
@ -324,13 +333,13 @@ class UiAdventure{
|
|||
//change resource data
|
||||
Control.set_events(amount){|event|
|
||||
if(event.type == UIEvent.change){
|
||||
var value = Math.clamp(event.change.round, 0, resource["amount"])
|
||||
adventure.resources.set(resource["base_name"], value)
|
||||
var value = event.change.round
|
||||
adventure.resources.set(resource["name"], value)
|
||||
}
|
||||
}
|
||||
//change ui on resource data change
|
||||
var token = adventure.resources.on_change{|value|
|
||||
NumberField.set_value(amount, value.get(resource["base_name"]))
|
||||
NumberField.set_value(amount, Math.clamp(value.get(resource["name"]), 0, resource["amount"]))
|
||||
}
|
||||
_itemEvents.add(token)
|
||||
_itemListItems.add(item)
|
||||
|
|
@ -345,9 +354,6 @@ class UiAdventure{
|
|||
Control.child_add(_root, page)
|
||||
UILayout.set_behave(_ent, page, UILayoutBehave.fill)
|
||||
UILayout.set_margin(_ent, page, 0, 0, 0, 16)
|
||||
_page.on_change(true){|val|
|
||||
Control.set_visible(page, val == UiAdventure.depart)
|
||||
}
|
||||
|
||||
var ready = UILabel.create(_ent)
|
||||
Control.child_add(page, ready)
|
||||
|
|
@ -366,8 +372,6 @@ class UiAdventure{
|
|||
UILabel.set_font(go, _ui.font)
|
||||
UILabel.set_text_size(go, 16)
|
||||
UILabel.set_text(go, "GO")
|
||||
UILabel.set_color(go, [1,1,1,1])
|
||||
UILabel.set_color_hover(go, [1,1,1,1])
|
||||
UILayout.set_behave(_ent, go, UILayoutBehave.left | UILayoutBehave.top) //|
|
||||
UILayout.set_margin(_ent, go, 56, 24, 0, 0)
|
||||
Clickable.make_clickable(go)
|
||||
|
|
@ -375,48 +379,14 @@ class UiAdventure{
|
|||
UILabel.set_text(go, data["hover"]?"GO!":"GO")
|
||||
}
|
||||
Clickable.set_on_click(go){
|
||||
_game.adventures.dispatch()
|
||||
}
|
||||
}
|
||||
|
||||
abort(){
|
||||
var page = Control.create(_ent)
|
||||
Control.child_add(_root, page)
|
||||
UILayout.set_behave(_ent, page, UILayoutBehave.fill)
|
||||
UILayout.set_margin(_ent, page, 0, 0, 0, 16)
|
||||
_page.on_change(true){|val|
|
||||
Control.set_visible(page, val == UiAdventure.abort)
|
||||
}
|
||||
|
||||
var ready = UILabel.create(_ent)
|
||||
Control.child_add(page, ready)
|
||||
Control.set_size(ready, 100, 10)
|
||||
UILabel.set_align_vertical(ready, TextAlign.bottom)
|
||||
UILabel.set_font(ready, _ui.font)
|
||||
UILabel.set_text_size(ready, 8)
|
||||
UILabel.set_text(ready, "This will discard the adventure")
|
||||
UILayout.set_behave(_ent, ready, UILayoutBehave.left | UILayoutBehave.top) //|
|
||||
UILayout.set_margin(_ent, ready, 12, 0, 0, 0)
|
||||
UILabel.set_color(ready, [0.7, 0.7, 0.7, 1])
|
||||
|
||||
var abort = UILabel.create(_ent)
|
||||
Control.child_add(page, abort)
|
||||
Control.set_size(abort, 100, 20)
|
||||
UILabel.set_align_vertical(abort, TextAlign.bottom)
|
||||
UILabel.set_align(abort, TextAlign.right)
|
||||
UILabel.set_font(abort, _ui.font)
|
||||
UILabel.set_text_size(abort, 16)
|
||||
UILabel.set_text(abort, "ABORT")
|
||||
UILabel.set_color(abort, [1,1,1,1])
|
||||
UILabel.set_color_hover(abort, [1,1,1,1])
|
||||
UILayout.set_behave(_ent, abort, UILayoutBehave.left | UILayoutBehave.top) //|
|
||||
UILayout.set_margin(_ent, abort, 25, 8, 0, 0)
|
||||
Clickable.make_clickable(abort)
|
||||
Clickable.set_state_change(abort){ |data, button|
|
||||
UILabel.set_text(abort, data["hover"]?"ABORT!":"ABORT")
|
||||
}
|
||||
Clickable.set_on_click(abort){
|
||||
//todo, start adventure, not discard!!
|
||||
_ui.ui_mode = Ui.Info
|
||||
_game.adventures.discard()
|
||||
_page.value = UiAdventure.direction
|
||||
}
|
||||
|
||||
_page.on_change(true){|val|
|
||||
Control.set_visible(page, val == UiAdventure.depart)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,17 +36,21 @@ class UiCompass{
|
|||
Control.set_process(compass){|control, state, event, x,y,w,h|
|
||||
if(event.control != control) return
|
||||
|
||||
System.print("event: %(event) - currently captured: %(UI.get_captured(ent))")
|
||||
|
||||
if(event.type == UIEvent.press){
|
||||
var relative_pos = AABB.new(x, y, w, h).relative_pos([event.x, event.y])
|
||||
var inside = M.length(relative_pos.map{|comp| comp - 0.5}) < 0.5
|
||||
if(inside) {
|
||||
state["pressed"] = true
|
||||
UI.capture(control)
|
||||
System.print("CAPTURE COMPASS")
|
||||
}
|
||||
}
|
||||
if(event.type == UIEvent.release){
|
||||
state["pressed"] = false
|
||||
UI.uncapture(control)
|
||||
System.print("UNCAPTURE COMPASS")
|
||||
}
|
||||
if((event.type == UIEvent.move || event.type == UIEvent.press) && state["pressed"]){
|
||||
var center = [x + w/2, y + h/2]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import "globals" for Globals
|
|||
import "math/rect" for AABB
|
||||
import "math/math" for M
|
||||
import "blocks/debug" for DrawDebug
|
||||
import "math/util" for Util
|
||||
|
||||
class UiSlider{
|
||||
static horizontal{"horiz"}
|
||||
|
|
@ -51,7 +50,6 @@ class UiSlider{
|
|||
}
|
||||
Control.set_process(slider){|control, state, event, x,y,w,h|
|
||||
if(event.control != control) return
|
||||
if(!Util.valid_event(event)) return
|
||||
if(event.type == UIEvent.press){
|
||||
state["pressed"] = true
|
||||
UI.capture(control)
|
||||
|
|
|
|||
|
|
@ -1,28 +1,6 @@
|
|||
//a lot of this is bad and can only handle ASCII
|
||||
//too bad ¯\_(ツ)_/¯
|
||||
|
||||
|
||||
class StringUtil{
|
||||
static directions{
|
||||
if(!__directions){
|
||||
var step_names = ["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
|
||||
__directions= step_names.map{|short|
|
||||
var shorts = "NESW"
|
||||
var base_directions = ["north","east","south","west"]
|
||||
if(short.count == 1){
|
||||
return base_directions[shorts.indexOf(short)]
|
||||
} else if(short.count == 2) {
|
||||
return base_directions[shorts.indexOf(short[0])] +
|
||||
base_directions[shorts.indexOf(short[1])]
|
||||
} else { //assume 3
|
||||
return base_directions[shorts.indexOf(short[0])] + "-" +
|
||||
base_directions[shorts.indexOf(short[1])] +
|
||||
base_directions[shorts.indexOf(short[2])]
|
||||
}
|
||||
}.toList
|
||||
}
|
||||
return __directions
|
||||
}
|
||||
|
||||
static possesive(string){
|
||||
if(string.endsWith("s")){
|
||||
return "%(string)'"
|
||||
|
|
@ -42,82 +20,26 @@ class StringUtil{
|
|||
//todo: this doesnt cover all cases perfectly, add more
|
||||
static a(string){
|
||||
var firstChar = string[0]
|
||||
if(is_vowel(firstChar)){
|
||||
if(isVowel(firstChar)){
|
||||
return "an %(string)"
|
||||
} else {
|
||||
return "a %(string)"
|
||||
}
|
||||
}
|
||||
|
||||
static is_vowel(char){
|
||||
static isVowel(char){
|
||||
return "aeiou".contains(char)
|
||||
}
|
||||
|
||||
static direction(index){
|
||||
return directions[index]
|
||||
}
|
||||
|
||||
//checks if a character (as codepoint is lowercase)
|
||||
static is_lower(char){
|
||||
return char >= 97 && char <= 122
|
||||
}
|
||||
|
||||
//checks if a character (as codepoint is uppercase)
|
||||
static is_upper(char){
|
||||
return char >= 65 && char <= 90
|
||||
}
|
||||
|
||||
static is_letter(char){
|
||||
return is_lower(char) || is_upper(char)
|
||||
}
|
||||
|
||||
static to_upper(string){
|
||||
return string.codePoints.map{|c|is_lower(c)?c-32:c}.map{|c|String.fromCodePoint(c)}.join()
|
||||
}
|
||||
|
||||
static to_lower(string){
|
||||
return string.codePoints.map{|c|is_upper(c)?c+32:c}.map{|c|String.fromCodePoint(c)}.join()
|
||||
}
|
||||
|
||||
//todo: do
|
||||
static capitalize(string){
|
||||
return to_upper(string[0]) + string[1..-1]
|
||||
return string
|
||||
}
|
||||
|
||||
//todo: this ignores words that arent preceeded by a space like (this) or "this". maybe fix that?
|
||||
//todo: ths ignores words that arent preceeded by a space like (this) or "this". maybe fix that?
|
||||
static capitalize_all(string){
|
||||
//split by words/stuff between words and capitalize everything,
|
||||
//capitalize function doesnt know what to do with separators so it wont touch them
|
||||
return WordSequence.new(string).map{|word| capitalize(word)}.join()
|
||||
}
|
||||
}
|
||||
|
||||
class WordSequence is Sequence{
|
||||
static new(string){
|
||||
return new(string) {|c|
|
||||
return StringUtil.is_letter(c)
|
||||
}
|
||||
}
|
||||
|
||||
construct new(string, letterCheck){
|
||||
_string = string
|
||||
_check = letterCheck
|
||||
}
|
||||
|
||||
iterate(iterator){
|
||||
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
|
||||
var is_word = StringUtil.is_letter(_string.codePointAt_(start))
|
||||
var end = start + 1
|
||||
//count up until you find something thats not a word/separator depending on what the first letter was
|
||||
while(end < _string.count && StringUtil.is_letter(_string.codePointAt_(end)) == is_word){
|
||||
end = end + 1
|
||||
}
|
||||
end = end - 1
|
||||
return [start, end, is_word]
|
||||
}
|
||||
|
||||
iteratorValue(iterator){
|
||||
return _string[iterator[0]..iterator[1]]
|
||||
var words = string.split(" ")
|
||||
words = words.map{|word| capitalize(word)}
|
||||
return words.join(" ")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue